ListView Footerview没有占据全宽

时间:2016-05-27 05:26:02

标签: android

这是我的页脚视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="1">

    <Button
        android:id="@+id/button_add_location1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin_top_10"
        android:layout_weight="1"
        android:text="+ Add more location"
        android:textColor="@color/grey3"
        android:textSize="@dimen/size_15" />

</LinearLayout>

以下是我如何充气我的listView footerview

 View footerView1 = View.inflate(mContext, R.layout.layout_footerview1, null);
        listView1.addFooterView(footerView1);

页脚视图,即按钮的宽度不是match_parent,而是宽度为wrap_content。

请帮助我实现我的结果。提前谢谢。

2 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="1">

    <Button
        android:id="@+id/button_add_location1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin_top_10"
        android:layout_weight="1"
        android:text="+ Add more location"
        android:textColor="@color/grey3"
        android:textSize="@dimen/size_15" />

</LinearLayout>

答案 1 :(得分:0)

你应该尝试没有一些属性,并设置ListView的高度和宽度fill_parent
android:weightSum="1"

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <Button
        android:id="@+id/button_add_location1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="+ Add more location"/>

</LinearLayout>

如果仍然无法正常工作,你应该尝试在java中设置填充,如...

View footer = LayoutInflater.from(this).inflate(R.layout.footer_button,
            null);
    footer.setPadding(100, 0, 100, 0);//first is for left and secon 100 for right.