代码之家  ›  专栏  ›  技术社区  ›  Jay Askren

如何在listview上下放置小部件?

  •  6
  • Jay Askren  · 技术社区  · 16 年前

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
    
        <TextView android:id="@+id/footer" 
            android:text="footer"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:layout_alignParentBottom="true"
            />
    
        <ListView  android:id="@+id/list_view" 
            android:layout_height="fill_parent" 
            android:layout_width="fill_parent"
            android:layout_above="@id/footer"
            android:background="#ff9999ff"/>
    
        <TextView android:id="@+id/header" 
            android:text="header"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:layout_alignParentTop="true"
            android:layout_above="@id/list_view"
            android:baselineAlignBottom="false"
            />
    
    </RelativeLayout>
    

    public class SampleListActivity extends Activity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.list_activity);
    
        }
    }
    
    4 回复  |  直到 16 年前
        1
  •  10
  •   Jay Askren    16 年前

    我无法在android1.5中使用相对布局,但我确实使用了线性布局。下面是我的解决方案:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:orientation="vertical">
    
        <TextView android:id="@+id/header" 
            android:text="header"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:layout_weight="0"
            />
        <ListView  android:id="@+id/list_view" 
            android:layout_height="fill_parent" 
            android:layout_width="fill_parent"
            android:background="#ff9999ff"
            android:layout_weight="1"/>
    
        <TextView android:id="@+id/footer" 
            android:text="footer"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:layout_weight="0"
            />
    </LinearLayout>
    
        2
  •  5
  •   JoséMi    13 年前

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    
        <TextView android:id="@+id/header" 
            android:text="header"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" />
    
        <TextView android:id="@+id/footer" 
            android:text="footer"
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:layout_alignParentBottom="true"/>
    
        <ListView android:id="@id/android:list" 
            android:layout_height="fill_parent" 
            android:layout_width="fill_parent"
            android:layout_below="@id/header"
            android:background="#ff9999ff"/>
    
    </RelativeLayout>
    

    编辑

        3
  •  2
  •   CommonsWare    16 年前

    android:layout_below="@id/header" 添加到 ListView .

    android:layout_below="@+id/header" 或许可以去掉 + 从当前签名 android:id="@+id/header" 中的属性 TextView .

    RelativeLayout ,从1.6开始,只要ID值的第一次出现具有 签字。

        4
  •  -1
  •   Beto    12 年前

    您只需在线性布局中的列表中添加权重1,其他文本视图/按钮/等不需要任何权重值。

    举个例子: https://bitbucket.org/generalplus/android_development/src/5a892efb0551/samples/ApiDemos/res/layout/linear_layout_9.xml