Android ListView页脚视图未放置在屏幕底部

Geo*_* II 15 android listview footer

我确信我错过了一些简单的方法来实现这一点,但是我已经完成了所有已知的组合,以便得到我正在寻找的工作.当ListView项目没有填满页面时,我正试图让ListView页脚位于屏幕底部.

例如,我有一个包含三个项目的ListView的页面和一个FooterView(使用ListView的addFooterView)我希望footerView位于屏幕的底部.当ListView包含足够的项目来滚动屏幕时,footerView应该位于列表的末尾(而不是位于屏幕的底部).

我正在尝试使用的XML如下所示.任何和所有的帮助非常感谢!

Layout.xml

<?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"
android:background="@+drawable/background">
<ListView
    android:id="@+id/menu" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:listSelector="@android:color/transparent"
    android:divider="@null">
</ListView></RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

ListViewRow.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
style="@style/Nationwide.menu">
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/nav_item"
    style="@style/Nationwide.menu.row">
    <ImageView 
        android:id="@+id/image_icon"
        style="@style/Nationwide.menu.leftIcon" />
    <TextView 
        android:id="@+id/nav_text" 
        style="@style/Nationwide.menu.text" />
    <ImageView
        android:id="@+id/chevron_symbol"
        style="@style/Nationwide.menu.rightIcon" />
</LinearLayout>
<View
    android:layout_height="1dp"
    android:background="@drawable/nav_item_divider_dark" />
<View
    android:layout_height="1dp"
    android:background="@drawable/nav_item_divider_light" /></LinearLayout>
Run Code Online (Sandbox Code Playgroud)

ListViewFooter.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<View 
    android:id="@+id/footer_image"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true" /></RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Java的

    LayoutInflater inflater = this.getLayoutInflater();
    View footerView = inflater.inflate(R.layout.footer, null);

    footerView.findViewById(R.id.footer_image).setBackgroundDrawable(resources.getDrawable(R.drawable.cone_footer));

    mMenuListView.addFooterView(footerView);
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过的事情包括:

  • 添加页脚视图如上所示
  • 在ListView上添加可绘制资源作为背景(这导致ListView不会跨越屏幕的整个宽度,并且由于9-Patch可伸缩区域而以奇怪的方式滚动)
  • 将cone_footer添加为布局中的单独视图

提前致谢!

Com*_*are 16

我希望footerView位于屏幕的底部.

那不是多么addFooterView()有效.

当ListView包含足够的项目来滚动屏幕时,footerView应该位于列表的末尾(而不是位于屏幕的底部).

这也不是如何addFooterView()运作的.

如果你想要它与列表一起滚动(即,如果三个列表项占据屏幕的上半部分,页脚就在三个项目的正下方),然后使用addFooterView()...但是页脚总是滚动列表.

如果你不希望它与列表一起滚动,一种方法是使用a RelativeLayout作为你的父,将你的页脚锚定到屏幕的底部,并让ListView坐在顶部和页脚之间......但是页脚从不滚动.

  • 现在我再次阅读这篇文章,我一定不清楚设计师想要什么.他们希望页脚与此列表一起滚动,但需要注意:如果列表(包括页脚)小于屏幕,则强制页脚对齐到屏幕底部.否则,只需在最后一个listView行之后显示它. (2认同)

Geo*_* II 3

如果其他人正在寻找类似的答案,这就是我最终为解决问题所做的事情。由于我想要添加的“页脚”只是一个图像来填充屏幕中的一些空间(当视图很短时),并且 ListView 方法并不是我的实现真正需要的,所以我们最终得到了这个作为我们的 XML 布局:

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.example.android.apis"
    style="@style/company.mainContainer">

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <!-- enter page content here -->

        <View android:layout_height="0px" android:layout_weight="1"
            android:visibility="invisible" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:scaleType="fitXY"
            android:src="@drawable/footer_cone">
        </ImageView>

    </LinearLayout>

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

希望这对其他人有帮助!