[英]Two fragments in one Activity, proportions
我有兩個片段。 當我啟動Activity時,僅list_fragment
被添加到了container
它占據了100%的屏幕。 現在,我想將new_fragment
添加到同一容器中。 list_fragment
應該占據屏幕的80%, new_fragment
應該占據屏幕的20%(其余部分)。
list_fragment.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b6b6b6">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listViewRecs"
android:layout_gravity="left|center_vertical"
/>
</LinearLayout>
new_fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
容器:
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
</LinearLayout>
對於LinearLayout
比例,Android建議使用布局權重 。
為此,您應該將list_fragment
layout_weight
設置為8,將new_fragment
layout_weight
為2。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.