Marco Dinatsoli
Marco Dinatsoli

Reputation: 10580

android listview footer change width when landscape

I have a layout contains listview with footer, I add this footer programatically, Now I want to use landscape mode, I did everythieng, but I have a problem.

The footer in the portiet mode is fill parent width. but when I change to landscape it becomes wrape content.

help please.

this is how i add the footer programatically

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

landscape layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv_customer_profile_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:gravity="center"
        android:text="@string/tv_name"
        android:textColor="#025f7c"
        android:textSize="30sp"
        android:typeface="serif" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="15dip" >

        <ImageView
            android:id="@+id/iv_customer_profile_image"
            android:layout_width="0dip"
            android:layout_height="150dip"
            android:layout_weight="1"
            android:contentDescription="@string/iv_undefinedImage"
            android:paddingLeft="5dip"
            android:src="@drawable/totti" />

        <ListView
            android:id="@+id/lv_customer_profile_details"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:cacheColorHint="#00000000"
            android:paddingLeft="10dip"
            android:paddingRight="10dip" >
        </ListView>
    </LinearLayout>

</LinearLayout>

Upvotes: 0

Views: 319

Answers (2)

g00dy
g00dy

Reputation: 6778

You can try a similar solution given here:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
    ViewGroup parent = (ViewGroup) findViewById(R.id.host_layout);
    View footer = LayoutInflater.from(this).inflate(R.layout.footer_button, null);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        ViewGroup.LayoutParams.FILL_PARENT,
        ViewGroup.LayoutParams.FILL_PARENT); 
    parent.addView(view, params);
}

EDIT:

Taking a look at the xml, I noticed that the LinearLayout, which contains the ImageView and the ListView has this:

android:layout_height="wrap_content"

If I understood corretly, this is the layout which contains the footer button and it may look like as fill_parent in portrait, but try to see it on a larger screen.

Upvotes: 1

Gabe Sechan
Gabe Sechan

Reputation: 93614

Try manually setting the layouyt parameters for the view, to ensure its set to fill_parent for its width.

Upvotes: 0

Related Questions