我试图在单个 Activity
中垂直放置 3 个不同的 Fragment
。
我愿意:
- 为每个 Fragment 分配一个比例(最好是百分比)高度。
- fragment 应占据整个设备宽度。
- 根据旋转改变它的位移。
这是我的 Activity 布局的样子:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical" >
<fragment
android:id="@+id/messageFragment"
android:name="apps.android.expressa.expressa.Fragments.MessageFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@layout/message_fragment_layout" />
<fragment
android:id="@+id/listsFragment"
android:name="apps.android.expressa.expressa.Fragments.ListsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="@layout/lists_fragment_layout" />
<fragment
android:id="@+id/bottomBarFragment"
android:name="apps.android.expressa.expressa.Fragments.BottomBarFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
tools:layout="@layout/bottom_bar_layout" />
</LinearLayout>
问题是现在,只有第一个和第二个 fragment 显示,第三个只能看到顶部。请注意,我现在是 Android 的新手。
最佳答案
希望对你有帮助
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical"
android:weightSum="6" >
<fragment
android:id="@+id/messageFragment"
android:name="apps.android.expressa.expressa.Fragments.MessageFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="@layout/message_fragment_layout" />
<fragment
android:id="@+id/listsFragment"
android:name="apps.android.expressa.expressa.Fragments.ListsFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
tools:layout="@layout/lists_fragment_layout" />
<fragment
android:id="@+id/bottomBarFragment"
android:name="apps.android.expressa.expressa.Fragments.BottomBarFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
tools:layout="@layout/bottom_bar_layout" />
</LinearLayout>
关于android - 如何为 LinearLayout 中的 Fragments 分配比例尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29530845/