开发者

ListView Not Showing Below RelativeLayout

This is a rather odd issue which I can't seem to solve no matter how many times I stare at it (so it probably has an obvious answer). The issue is that when I have my RelativeLayout/ActionBar in the layout XML doc, the ListView below doesn't want to show up on screen when debugging. Here's my XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/LinearLayout01"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" >

      <RelativeLayout 
           android:orientation="horizontal" 
           android:layout_width="fill_parent"
           android:l开发者_如何学Cayout_height="50dip" 
           android:background="#4a8bcc" android:id="@+id/relLayout" >

               <TextView 
                    android:layout_width="wrap_content" 
                    android:layout_centerVertical="true"
                    android:textSize="7pt"
                    android:textColor="#ffffff"
                    android:textStyle="bold" 
                    android:layout_height="wrap_content"
                    android:text="List" android:padding="8dp" />

            <!-- A dividing line -->
               <ImageView 
                    android:layout_width="1px" 
                    android:src="#ffffffff"
                    android:layout_height="wrap_content" 
                    android:text="@string/hello"
                    android:id="@+id/bordertwo" 
                    android:layout_toLeftOf="@+id/refresh"
                    android:layout_marginRight="12dip" 
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentTop="true" />

         <!-- share button -->
              <ImageView 
                    android:layout_width="25dip" 
                    android:src="@drawable/ic_title_share_default"
                    android:layout_height="25dip" 
                    android:text="@string/hello"
                    android:layout_marginRight="12dip" 
                    android:layout_centerVertical="true"
                    android:id="@+id/refresh" 
                    android:layout_toLeftOf="@+id/borderone"
                    android:scaleType="fitXY" />

           <!-- A dividing line -->
              <ImageView 
                    android:layout_width="wrap_content" 
                    android:src="#ffffffff" 
                    android:layout_height="wrap_content"
                    android:id="@+id/borderone"  
                    android:layout_alignParentTop="true"
                    android:layout_marginRight="12dip" 
                    android:layout_alignParentBottom="true"
                    android:layout_alignBottom="@+id/search"  
                    android:text="@string/hello"
                    android:layout_toLeftOf="@+id/search" />

            <!-- Add friend -->
             <ImageView 
                    android:src="@drawable/ic_title_add_default" 
                    android:text="@string/hello"
                    android:layout_width="25dip" 
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"  
                    android:id="@+id/search"
                    android:layout_marginRight="12dip" 
                    android:layout_height="25dip"
                    android:scaleType="fitXY" />
     </RelativeLayout>

     <LinearLayout 
          android:orientation="horizontal"             
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="#4a8bcc" android:id="@+id/linLayout" 
          android:visibility="visible">

          <ListView 
               android:id="@+id/ListView01"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent" />
      </LinearLayout>
</LinearLayout>


 android:orientation="vertical"

on both LinearLayout (s) You really don't need the second one, because it has only one child. But if you must set weight=1 on it. ListView should look like this ( after you drop LinearLayout )

<ListView
            android:id="@+id/ListView01"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1.0"
            />

And read more about Layouts here http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

If you still want to wrap your list around with layout follow this sample http://developer.android.com/resources/samples/ApiDemos/res/layout/list_8.html


Why do you have your ListView in a LinearLayout? With size set to wrap_content? That doesn't make much sense. Just add the ListView directly, and set the layout_height="fill_parent". This should cause it to take up all available space.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜