Amour Ring
Amour Ring

Reputation: 141

layout doesn't show

please look my code fist ,I want to make the layout like below picture ,but the two listViews not work :

<?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>

I want to realize the layout like the image below:

enter image description here

but the two listView doesn't show at all , what i have missed? someone help me please.thank you.

Upvotes: 1

Views: 576

Answers (1)

nlt
nlt

Reputation: 555

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

Yes it is, have a look at these questions :
Android: trying to understand android:layout_weight
Need help in understand layout_weight="1"

So here is my suggesttion:

<?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>

When you run the app, you will see that the LinearLayout wrap 2 ListView have different background colors, so the ListView are shown, so I think the problem is that you forget to set Adapter for them. Give it a try and please tell me the result.

Upvotes: 1

Related Questions