Note that there are some explanatory texts on larger screens.

plurals
  1. POListView pushes other Views off the screen
    primarykey
    data
    text
    <p>I'm struggling to get a layout looking correctly, and I've tried to produce the shortest, smallest possible example of my problem.</p> <p>My goal is to have a header and footer View, at the top and bottom of the screen, with a <code>ListView</code> in between the two, with another View (let's call it the <em>label</em>, it's the gray box from the screen shots) directly below the <code>ListView</code>. This label, and the footer should always be shown when <code>ListView</code> needs to scroll.</p> <h2>Visual Result</h2> <p>When the <code>ListView</code> does not need to scroll (this is correct):</p> <p><img src="https://i.stack.imgur.com/TIERQ.png" alt="when the ListView doesn&#39;t need to scroll"></p> <p>When the <code>ListView</code> needs to scroll, the footer and the gray box are pushed off screen (wrong):</p> <p><img src="https://i.stack.imgur.com/Uum7E.png" alt="when the ListView needs to scroll"></p> <h2>Layout</h2> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="header" android:padding="20dp" android:textSize="18sp" android:background="@color/red"/&gt; &lt;ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/list" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="this should be directly below the ListView, but not pushed off screen when the ListView needs to scroll" android:padding="5dp" android:background="@color/light_gray" android:textColor="@color/black"/&gt; &lt;!-- Used to push the footer to the bottom --&gt; &lt;View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1"/&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="footer" android:padding="20dp" android:textSize="18sp" android:background="@color/blue"/&gt; &lt;/LinearLayout&gt; </code></pre> <h2>Test Activity</h2> <pre><code>public class TestActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ArrayList&lt;String&gt; items = new ArrayList&lt;String&gt;(); items.add("one"); items.add("two"); items.add("three"); items.add("four"); items.add("five"); items.add("six"); items.add("seven"); items.add("eight"); items.add("nine"); items.add("ten"); setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.simple_list_item_1, items)); setContentView(com.myproject.android.R.layout.test); } } </code></pre> <p>I've tried a few different approaches, such as giving the <code>ListView</code> <code>layout_weight="1"</code> and removing the blank <code>View</code> that I use to push the footer to the bottom. This is almost what I want, it keeps the footer and label visible when the <code>ListView</code> scrolls, but when it only has 1 or 2 items, I need the gray box right below the <code>ListView</code>. I've also attempted to use a <code>RelativeLayout</code>, without success. I guess I'm completely misunderstanding things.</p> <h2>EDIT</h2> <p>Here's my attempt with a <code>RelativeLayout</code> which still isn't correct.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="header" android:padding="20dp" android:textSize="18sp" android:background="@color/red" android:id="@+id/header" /&gt; &lt;ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/list" android:layout_below="@id/header"/&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="this should be directly below the ListView, but not pushed off screen when the ListView needs to scroll" android:padding="5dp" android:background="@color/light_gray" android:textColor="@color/black" android:layout_below="@android:id/list"/&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="footer" android:padding="20dp" android:textSize="18sp" android:background="@color/blue" android:layout_alignParentBottom="true" android:id="@+id/footer"/&gt; &lt;/RelativeLayout&gt; </code></pre> <h2>Relative Layout (Still Wrong):</h2> <p><img src="https://i.stack.imgur.com/72524.png" alt="relative layout attempt"></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.
 

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