【问题标题】:Android: Footer in a ListViewAndroid:ListView 中的页脚
【发布时间】:2011-10-20 13:16:24
【问题描述】:

我有一个如下的列表视图

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:background="#E6E7E2">
    <ImageView android:id="@+id/Thumbnail" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/icon" />
    <TextView android:id="@+id/FilePath" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:textColor="#E6E7E2"
        />
</LinearLayout>

我的页脚如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:layout_gravity="bottom">
    <LinearLayout android:layout_width="fill_parent" 
            android:layout_alignParentBottom="true" 
            android:layout_height="wrap_content"
            android:id="@+id/layoutfooterbutton" android:layout_gravity="bottom">

            <Button android:layout_weight=".30" android:layout_margin="2dp"
                android:layout_height="60dp" android:layout_width="100dp"
                android:textColor="#FFF" android:gravity="bottom|center"
                android:textSize="12dp" android:id="@+id/ButtonAudio" android:background="@drawable/vid_red"/>

            <Button android:layout_weight=".30" android:layout_height="60dp" android:layout_width="100dp"
                android:gravity="bottom|center" android:background="@drawable/redblank"
                android:textColor="#E6E7E2" android:id="@+id/ButtonBrowse" android:layout_marginTop="2dp"/>
            <Button android:layout_weight=".30" android:layout_margin="2dp"
                android:layout_height="60dp" android:layout_width="100dp"
                android:textColor="#FFF" android:gravity="bottom|center"
                android:textSize="12dp" android:background="@drawable/reddelete" android:id="@+id/ButtonDelete"/>

        </LinearLayout>
</RelativeLayout>

当我使用

将页脚添加到列表视图时
View header = getLayoutInflater().inflate(R.layout.header, null);
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView lv = getListView();

// setting header for the list view
lv.addHeaderView(header);
lv.addFooterView(footer);
setListAdapter(new ArrayAdapter<String>(AudioListActivity.this, R.layout.row_audio,  R.id.label, db_results));

它位于最后一个列表视图项的正下方。我希望页脚位于底部。我怎样才能实现它??

PS:标题完美地位于顶部。

提前感谢您的时间。

【问题讨论】:

  • listview的布局在哪里?
  • 我没有单独的 ListView 布局。我已经给出了上面的 listview 代码,并且在代码中我检索了代码。有没有办法在一个布局中包含 listview 和 header fooer 并实现?请澄清一下。
  • 这个LInk 有完美的例子,只是看看....也检查这个问题...amongst us

标签: android xml listview android-layout footer


【解决方案1】:

它按预期工作。页脚视图将位于列表的底部。如果你想在屏幕底部有一些静态的东西,你需要使用 RelativeLayout 和你的页脚作为 alignParentBottom 并在它的顶部列出。

啊,我发现了另一个类似的问题,答案也是一样的:)

Android ListView Footer View not being placed on the bottom of the screen

【讨论】:

  • 你做了什么,现在得到了什么?
  • 我将页脚的顶部布局更改为列表视图布局,仍然相同。没有改变。我希望页脚固定在底部。似乎无法通过 android 实现这一目标
【解决方案2】:

对于您的情况,我认为您需要类似的东西。

<RelativeLayout>
    <include android:id="@+id/header" layout="@layout/header" android:layout_width="fill_parent" android:layout_alignParentTop="true" />

    <include android:id="@+id/footer" layout="@layout/footer" android:layout_width="fill_parent" android:layout_alignParentBottom="true" /> 

    <ListView android:layout_below="@id/header" android:layout_above="@id/footer"/> 
</RelativeLayout>

【讨论】:

    【解决方案3】:

    试试这个..

    <ListView
            android:id="@+id/your_id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:listfooter="@layout/your_layout" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 2012-03-20
      • 2011-04-12
      • 1970-01-01
      相关资源
      最近更新 更多