0

我尝试显示两个窗格的 UI 设计。我尝试在具有权重的线性布局中添加两个片段。但是,线性布局似乎忽略了权重。我该如何纠正?谢谢

[链接:] http://dl.dropbox.com/u/78582670/twopanes.png

我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<fragment
    class="com.usci.view.fragment.CatalogFragment"
    android:id="@+id/fragment_catalog"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="0.2">
</fragment>

<fragment
    class="com.usci.education.TestFragment1"
    android:id="@+id/fragment_test"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="0.8">
</fragment>

</LinearLayout>

解决方案:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<fragment
    class="com.usci.view.fragment.CatalogFragment"
    android:id="@+id/fragment_catalog"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="8">
</fragment>

<fragment
    class="com.usci.education.TestFragment1"
    android:id="@+id/fragment_test"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="2">
</fragment>

</LinearLayout>
4

3 回答 3

4

总是,当您使用权重时,将(孩子的)宽度/高度设置为 0px,并且更喜欢整数作为权重。

所以,解决方案是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<fragment
    class="com.usci.view.fragment.CatalogFragment"
    android:id="@+id/fragment_catalog"
    android:layout_width="0px"
    android:layout_height="match_parent"
    android:layout_weight="2">
</fragment>

<fragment
    class="com.usci.education.TestFragment1"
    android:id="@+id/fragment_test"
    android:layout_width="0px"
    android:layout_height="match_parent"
    android:layout_weight="8">
</fragment>

</LinearLayout>
于 2012-07-30T08:54:30.983 回答
0

和我一起工作,把 20,80 .. 也试试0.8,0.2

<fragment
class="com.usci.view.fragment.CatalogFragment"
android:id="@+id/fragment_catalog"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.8">
</fragment>

<fragment
    class="com.usci.education.TestFragment1"
    android:id="@+id/fragment_test"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="0.2">
</fragment>
于 2012-07-30T07:38:04.497 回答
0

设置 android:layout_width 和 android:layout_height 值 match_parent,然后例如设置 android:layout_weight (1 fragment 和 2 fragment) 值 1

于 2012-07-30T07:45:15.967 回答