Marco Dinatsoli
Marco Dinatsoli

Reputation: 10570

android listview footer width changed to match parent itself

I have an activity with portrait and landscape mode.

the activity contains listview. this listview has a footer, which I added programmatically like this:

View footer = LayoutInflater.from(this).inflate(R.layout.footer_button,
                null);
        footer.setPadding(0, 0, 0, 0);
lv_details.addFooterView(footer);

and the layout for the footer footer_button.xml is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

<Button android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/b_ok"
        android:text="@string/b_ok"
        android:textColor="#FFFFFF"
        android:background="@drawable/bg_selector"/>
</LinearLayout>

that works perfectly with the portrait mode. image when the footer (ok button) is correct enter image description here

Now when I go to landscape mode, I got the problem. here is what the footer became enter image description here

I go into the Hierachy viewer and I think I found the error, look at this photo please enter image description here as you see, the width is Match parent not fill parent even though I have used fill parent in my layout.

what is the solution please?

Code after someone asked to

adapter = new AdapterFoodProfile(this, aList);
        View header = LayoutInflater.from(this).inflate(
                R.layout.customer_profile_header, null);
        tv_edit = (TextView) header
                .findViewById(R.id.tv_customer_profile_header_edit);
        tv_edit.setOnClickListener(this);
        lv_details.addHeaderView(header);
        View footer = LayoutInflater.from(this).inflate(R.layout.footer_button,
                null);
        footer.setPadding(0, 0, 0, 0);
        b_ok = (Button) footer.findViewById(R.id.b_ok);
        b_ok.setOnClickListener(this);
        lv_details.addFooterView(footer);
        lv_details.setAdapter(adapter);

Upvotes: 1

Views: 1043

Answers (2)

g00dy
g00dy

Reputation: 6778

If this fixes the problem, even partially, as you did - the ListView has been set to android:layout_width="fill_parent". If another problem occurs it will be related to this one indirectly.

Upvotes: 2

nilesh patel
nilesh patel

Reputation: 832

Please set button width fill_parent.

Upvotes: 0

Related Questions