1

私のコードフィストを見てください、私は下の写真のようなレイアウトを作りたいのですが、2つのlistViewsは機能しません:

<?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="vertical" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="7"
        android:baselineAligned="false">
        <LinerLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"><!-- here is the problem-->

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusableInTouchMode="false"
                android:text="@string/Subdistrict"/>

            <ListView
                android:id="@+id/Subdistrict"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >     
            </ListView>   

        </LinerLayout>

        <LinerLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusableInTouchMode="false"
                android:text="@string/Building"
                android:textColor="#ffffff"/>
           <ListView
                android:id="@+id/Building"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
           </ListView>
        </LinerLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <Button 
            android:id="@+id/BuildingSelectOk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/OK"/>
        <Button 
            android:id="@+id/BuildingSelectCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Cancel"/>
    </LinearLayout>
</LinearLayout>

下の画像のようなレイアウトを実現したい:

ここに画像の説明を入力してください

しかし、2つのlistViewがまったく表示されません、私が見逃したものは何ですか?誰かが私を助けてください。ありがとう。

4

1 に答える 1

1
"height" to "0dp" though your list will calculate itself. and "weight" to 7? Is it needed?

はい、そうです、これらの質問を見てください:
Android:android:layout_weightを理解しようとして
いますlayout_weight="1"を理解するのに助けが必要です

だからここに私の提案があります:

<?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="vertical" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="80"
        android:baselineAligned="false">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#2fff0000"
            android:layout_weight="50">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusableInTouchMode="false"
                android:text="Subdistrict"/>

            <ListView
                android:id="@+id/Subdistrict"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >     
            </ListView>   

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#2f00ff00"
            android:layout_weight="50">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusableInTouchMode="false"
                android:text="Building"
                android:textColor="#ffffff"/>
           <ListView
                android:id="@+id/Building"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
           </ListView>
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="20"
        android:gravity="center" >

        <Button 
            android:id="@+id/BuildingSelectOk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="OK"/>
        <Button 
            android:id="@+id/BuildingSelectCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel"/>
    </LinearLayout>
</LinearLayout>

アプリを実行すると、LinearLayoutラップ2ListViewの背景色が異なるので、ListViewが表示されているので、アダプターを設定し忘れているのが問題だと思います。試してみて、結果を教えてください。

于 2013-03-01T03:53:32.230 に答える