[英]Two fragments in one Activity, proportions
I have two fragments. 我有两个片段。 When I start the Activity only
list_fragment
is added to the container
it takes 100% of the screen. 当我启动Activity时,仅
list_fragment
被添加到了container
它占据了100%的屏幕。 Now I want to add the new_fragment
to the same container. 现在,我想将
new_fragment
添加到同一容器中。 list_fragment
should take 80% of the screen and new_fragment
should take 20% of it (the rest). list_fragment
应该占据屏幕的80%, new_fragment
应该占据屏幕的20%(其余部分)。
list_fragment.xml: 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: 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>
container: 容器:
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
</LinearLayout>
For propotions in LinearLayout
android suggests using Layout Weights . 对于
LinearLayout
比例,Android建议使用布局权重 。
To achieve it you should set list_fragment
layout_weight
to 8, and new_fragment
layout_weight
to 2. 为此,您应该将
list_fragment
layout_weight
设置为8,将new_fragment
layout_weight
为2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.