Note that there are some explanatory texts on larger screens.

plurals
  1. POLimit height of ListView on Android
    primarykey
    data
    text
    <p>I want to show a button under a <code>ListView</code>. Problem is, if the <code>ListView</code> gets extended (items added...), the button is pushed out of the screen. </p> <p>I tried a <code>LinearLayout</code> with weights (as suggested in <a href="https://stackoverflow.com/questions/4054567/android-why-is-there-no-maxheight-for-a-view">Android: why is there no maxHeight for a View?</a>), but either I got the weights wrong or it simply didn't work. </p> <p>Also, I found somewhere the hint to use a <code>RelativeLayout</code>. The <code>ListView</code> would then be set above the button with the <code>android:layout_above</code> param. </p> <p>Problem with this is that I don't know how to position the button afterwards. In the example I found, the View below the <code>ListView</code> was adjusted using <code>android:layout_alignParentBottom</code>, but I don't want my button to cling to the bottom of the screen. </p> <p>Any ideas apart from using setHeight-method and some calculating of the required space?</p> <hr> <p>Edit: <strong>I got a lot of useful answers.</strong></p> <ul> <li><p>bigstone's &amp; user639183's solution <em>almost</em> worked perfectly. However, I had to add an extra padding/margin to the bottom of the button, as it still would be pushed half way out of the screen (but then stopped)</p></li> <li><p>Adinia's answer with the relative layout only is fine if you want the button fixed to the bottom of the screen. It's not what I intended but still might be useful for others.</p></li> <li><p>AngeloS's solution was the one I chose at the end as it just created the effects I wanted. However, I made two minor changes to the <code>LinearLayout</code> around the button: </p> <ul> <li><p>First, as I didn't want to have any absolute values in my layout, I changed <code>android:layout_height="45px"</code> to <code>wrap_content</code>, which works just fine as well. </p></li> <li><p>Second, as I wanted the button to be centered horizontally, which is only supported by vertical <code>LinearLayout</code>, I changed android:orientation="horizontal" to "vertical". </p></li> </ul> <p>AngeloS also stated in his initial post that he was not sure if the <code>android:layout_weight="0.1"</code> param in the <code>LinearLayout</code> around the <code>ListView</code> had any effect; I just tried and it actually does! Without, the button gets pushed out of the screen again.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload