Brian
Brian

Reputation: 8085

Laying out views below a ScrollView/ListView

My question is a bit specific, I have a ListView of items above a button all inside a dialog. I want my ListView to never be greater than 280dip but always have the button below the ListView, no matter how large this ListView may be. My concern is when the dialog is switched to landscape mode, the button disappears because it is pushed out of the view by the ListView above that I have set to have android:layout_height="280dip". Obviously, this means that the ListView will always be 280dip, but is there a way to make it so that the ListView can change its size so it can always fit the button below it no matter the screen size/dimensions? I don't want to fill the parent of the height in the dialog because I don't want the dialog to be stretched out all the way in portrait mode. I'm sure there is a simple solution to this, but I wasn't sure how to word it in a manner that was more general.

Upvotes: 1

Views: 999

Answers (2)

A. Abiri
A. Abiri

Reputation: 10810

If you want the button to always be right below the listview and keep it visible despite the varying screen sizes, just create a new layout that contains a button and initialize that layout in your java code. Then do listView1.addFooterView(layoutView) and the layout with the button will be attached to the bottom of the listview. This can help you further with setting a footer view to the listview.

View footerView = ((LayoutInflater)MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
listView1.addFooterView(footerView);

Upvotes: 2

Some Noob Student
Some Noob Student

Reputation: 14584

If you want a View to take up the rest of layout, you should set a weight for the View.

Try giving the following settings for the ListView and see what happens.

android:layout_weight="1"
android:layout_height="0dp"

Upvotes: 4

Related Questions