如何使用嵌套的FrameLayouts安排多个android片段?

时间:2012-08-04 22:47:38

标签: android android-fragments

我想显示一个简单的横向布局,在屏幕的左半部分有一个列表片段,在右边有两个垂直对齐的片段。水平显示所有三个片段工作正常,但我的布局下方仅显示列表片段,而不是右侧垂直LinearLayout内的其他两个片段。我的布局参数出了什么问题?

<?xml version="1.0" encoding="utf-8"?>
<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.copperykeenclaws.gameplanner.TeamListFragment"
        android:id="@+id/team_list_fragment"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="wrap_content">
   </fragment>
   <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <FrameLayout android:id="@+id/team_details_frame" 
                android:layout_width="0px" 
                android:layout_height="wrap_content"/>
        <FrameLayout android:id="@+id/team_players_frame" 
                android:layout_width="0px" 
                android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

FrameLayouts在FragmentTransactions中以编程方式替换,在全水平布局中工作正常。

1 个答案:

答案 0 :(得分:0)

team_details_frameteam_players_frame的宽度均为0px,因此他们不会显示。要么给它们一个layout_weight属性(虽然不鼓励使用嵌套的layout_weights,但我怀疑你的情况会有很多性能损失)或者将它们设置为wrap_content或match_parent。