1

当我学习片段时

http://developer.android.com/reference/android/app/Fragment.html

我在 layout-land/fragment_layout.xml 中看到了以下代码:

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

    <fragment class="com.example.android.apis.app.FragmentLayout$TitlesFragment"
            android:id="@+id/titles" android:layout_weight="1"
            android:layout_width="0px" android:layout_height="match_parent" />

    <FrameLayout android:id="@+id/details" android:layout_weight="1"
            android:layout_width="0px" android:layout_height="match_parent"
            android:background="?android:attr/detailsElementBackground" />

</LinearLayout>

为什么片段和框架布局的布局宽度都设置为零?我在纵向、设置上尝试了相同的 xml android:orientation="vertical",并显示了一个空白屏幕。那么里面有什么秘密呢?我的意思是垂直和水平之间有什么区别?那有什么特别之处FrameLayout呢?

4

2 回答 2

1

您正在寻找的是重量属性,它将您LinearLayout分成两个相等的部分。

秘密是android:layout_weight="1" 了解更多

于 2013-02-24T08:21:36.527 回答
0

如果您的 LinearLayout 是垂直方向,则具有 layout_weight 属性的每个项目都必须将 layout_height 设置为 0

在水平 LinearLayout 的情况下,如果它具有 layout_weight,则必须将 layout_width 设置为 0

于 2013-02-24T11:09:05.540 回答