Android 为什么我的碎片占据了整个屏幕的高度安卓
我有一个这样的布局:Android 为什么我的碎片占据了整个屏幕的高度安卓,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我有一个这样的布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/wrapper" android:layout_width="match_parent" android:layout_height="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<fragment
android:id="@+id/fragment_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="<headerClass>"/>
<fragment
android:id="@+id/fragment_body"
android:layout_below="@id/fragment_header"
android:layout_above="@+id/fragment_banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="<bodyClass>"/>
<fragment
android:id="@id/fragment_banner"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="<BannerClass>"/>
</RelativeLayout>
如您所见,高度设置为40dp
然而,标题占据了整个屏幕的高度。我不知道为什么。我在看LayoutFlater类,但是因为我不熟悉它,所以我看不出有什么问题。我用这条线来膨胀我的碎片:
View view = inflater.inflate(R.layout.fragment_header, container, false);
为什么它会显示这种行为?我如何修复它?我将每个片段放在自己的
线性布局中,并将第一个片段的高度设置为40dp,从而成功地修复了它。我不认为这是最好的解决方案,但这是我能想到的全部
View view = inflater.inflate(R.layout.fragment_header, container, false);