0

我正在尝试为我的应用程序制作两个窗格布局,并且我正在尝试使用layout_weight但它无法正常工作。看起来它被颠倒了,因此重量更大的视图更小,但是当我检查时它甚至没有这样做。这是我的xml:

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

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="1">

        <EditText
            android:id="@+id/etSearch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/search" >
            <requestFocus />
        </EditText>
        <ListView
            android:id="@+id/bookList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        </LinearLayout>


    <fragment
        android:id="@+id/fmtEditBook"
        android:layout_weight="2"
        android:layout_height="match_parent"
        android:layout_width="0dp"
        android:name="com.perlib.wmbg.fragments.EditBookFragment"
        tools:layout="@layout/fragment_edit_book" />
</LinearLayout>
4

2 回答 2

2

外部LinearLayout有宽度wrap_content,将其更改为match_parent

于 2014-06-28T23:00:37.457 回答
1

我不知道发生这种情况的确切原因,但是如果您layout_width将根元素更改为match_parent它将正常工作。

于 2014-06-28T23:01:23.460 回答