Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This type of behavior is too dynamic to define in XML, but it's easy enough to accomplish with a custom container view. I'm making a couple of assumptions about your application, primarily that the root layout of the Activity only has two children (the <code>ListView</code> and the footer view). Based on that, the following is a custom <code>LinearLayout</code> which will give you what you need:</p> <pre><code>public class ComboLinearLayout extends LinearLayout { public ComboLinearLayout(Context context) { super(context); } public ComboLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //We're cheating a bit here, letting the framework measure us first super.onMeasure(widthMeasureSpec, heightMeasureSpec); //Impose a maximum height on the first child View child = getChildAt(0); int newHeightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight() / 2, MeasureSpec.EXACTLY); if (child.getMeasuredHeight() &gt; (getMeasuredHeight() / 2)) { measureChild(child, widthMeasureSpec, newHeightSpec); } //Optional, make the second child always half our height child = getChildAt(1); measureChild(child, widthMeasureSpec, newHeightSpec); } } </code></pre> <p>Then you can apply this in your Activity layout like so:</p> <pre><code>&lt;com.example.myapplication.ComboLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&gt; &lt;ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content"/&gt; &lt;TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="Hi Mom!" android:background="#0A0"/&gt; &lt;/com.example.myapplication.ComboLinearLayout&gt; </code></pre> <p>The net effect of the container code is that it fixes the measured height of the <code>ListView</code> to exactly half the container height if and only if it measures itself larger than that. Otherwise, it allows the <code>ListView</code> to be smaller.</p> <p>There's a secondary trick I added in case you needed it, which is an optional block of code that forces the footer view to always be half the screen height. If you are setting the footer view to a fixed height in XML, you can probably remove that second section from <code>onMeasure()</code>. If you use that code, it will work best if the footer view is set to <code>match_parent</code> in XML.</p>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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