出於某種原因,我的框架佈局不會一直延伸到屏幕邊緣。爲什麼FrameLayout不能用作我的片段容器使用全屏寬度?
這裏是我的活動佈局:
<FrameLayout
android:id="@+id/contactInfoFragmentContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
</FrameLayout>
而且這裏是,我在的FrameLayout在運行時將孤片段佈局:
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="220dp"
app:srcCompat="@android:drawable/btn_dialog"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="0dp" />
<LinearLayout
android:id="@+id/thumbnailsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.05"
android:orientation="horizontal">
<HorizontalScrollView
android:id="@+id/Thumbnails"
android:layout_width="260dp"
android:layout_height="97dp">
</HorizontalScrollView>
<Button
android:id="@+id/addImage"
android:layout_width="wrap_content"
android:layout_height="96dp"
android:layout_weight="1.06"
android:text="Add image" />
</LinearLayout>
<LinearLayout
android:id="@+id/shopNameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Name" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:id="@+id/phoneNumberLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Phone" />
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<EditText
android:id="@+id/phoneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:id="@+id/addressLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/addressText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPostalAddress" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
我只是做這個添加的片段在我的onCreate方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_shop);
// Check that the activity is using the layout version with
// the fragment_container FrameLayout
if (findViewById(R.id.contactInfoFragmentContainer) != null) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
return;
}
// Create a new Fragment to be placed in the activity layout
ContactInfoFragment firstFragment = new ContactInfoFragment();
// In case this activity was started with special instructions from an
// Intent, pass the Intent's extras to the fragment as arguments
firstFragment.setArguments(getIntent().getExtras());
// Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction()
.add(R.id.contactInfoFragmentContainer, firstFragment).commit();
}
}
那麼是什麼問題?當我在設計視圖中查看碎片佈局時,它看起來很好!
這個問題似乎只出現添加片段到我的活動佈局後(見上面的代碼和佈局)。我應該如何解決這個問題?
編輯:我不明白爲什麼我收到了投票。至少您可以留下評論,解釋問題的錯誤。
你的活動佈局是什麼樣子? – dhiku
@dhiku它是在問題「這是我的活動佈局:」... –
爲什麼-1?這是一個合法的問題! –