簡體   English   中英

一個活動中的兩個片段,比例

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM