【问题标题】:ListView footer widthListView 页脚宽度
【发布时间】:2013-07-24 07:01:45
【问题描述】:

列表视图的页脚有问题(我无法将页脚居中)。

我将页脚用于无限列表。

我遇到的问题是页脚没有被拉伸以匹配列表宽度(而是以某种方式使用 wrap_content)。

这是页脚布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/footer_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:gravity="center"
    android:padding="10dp" >

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="Loading more..." />

</LinearLayout>

这就是我将页脚添加到列表视图的方式:

View footerView;

...     

// Get the custom layout for footer
        footerView = getActivity().getLayoutInflater().
                inflate(R.layout.list_footer_load_more, getListView(), false);
        LinearLayout footerViewLayout = (LinearLayout) footerView.findViewById(R.id.footer_layout);
        // Adding custom view to ListView at footer
        getListView().addFooterView(footerViewLayout, null, false);

这就是最终结果的样子: (我无法在 stackoverflow 上发布图片,但这是图片的外部链接) http://s21.postimg.org/3zkd7pic7/listview_footer_problem.png

我尝试了一切使页脚居中但没有任何效果。我希望有人可以帮助我,因为这让我有一段时间压力很大。

谢谢。

【问题讨论】:

    标签: android listview layout footer


    【解决方案1】:

    将您的页脚布局(R.layout.list_footer_load_more)更改为:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/footer_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
    
            <ProgressBar
                android:id="@+id/progressBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical" />
    
            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:layout_gravity="center_vertical"
                android:text="Loading more..." />
    
        </LinearLayout>
    </RelativeLayout>  
    

    将您的代码更改为:

    View footerView;
    
    ...     
    
    // Get the custom layout for footer
    footerView = getActivity().getLayoutInflater().
                inflate(R.layout.list_footer_load_more, null);
    RelativeLayout footerViewLayout = (RelativeLayout) footerView.findViewById(R.id.footer_layout);
        // Adding custom view to ListView at footer
        getListView().addFooterView(footerViewLayout, null, false);
    

    【讨论】:

    • 可惜还是一样
    • @IonutNegru 而且,当膨胀R.id.footer_layout时,使用inflate(R.layout.list_footer_load_more, null);
    • 它仍然对齐错误......而且它有点小车(它移动了一点:) - 不知道为什么)
    • @IonutNegru 不知道出了什么问题。可能这里的其他人可以帮助您。
    • 天啊,我发现了问题...列表是通过片段加载的` ` 我忘了在这里设置宽度为 match_parent ...现在它就像我想要的那样工作:) ...无论如何感谢所有帮助...我会将您的答案标记为正确,因为这仍然是一种加载页脚的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多