Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid. Scrolling 2 listviews together
    primarykey
    data
    text
    <p>OK. What I'm trying to achieve is a layout that does the same effect as frozen panes in Excel. That is I want a header row that scrolls horizontally with the main ListView and a left hand ListView that scrolls vertically with the main ListView. The header row and the left hand listview should remain stationary when scrolling in the other dimension.</p> <p>Here is the xml layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/recordViewLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"&gt; &lt;LinearLayout android:layout_width="160dp" android:layout_height="match_parent" android:orientation="vertical"&gt; &lt;CheckBox android:id="@+id/checkBoxTop" android:text="Check All" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;ListView android:id="@+id/engNameList" android:layout_width="160dp" android:layout_height="wrap_content"/&gt; &lt;/LinearLayout&gt; &lt;HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:id="@+id/scroll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;include layout="@layout/record_view_line" android:id="@+id/titleLine" /&gt; &lt;ListView android:id="@android:id/list" android:layout_height="wrap_content" android:layout_width="match_parent"/&gt; &lt;/LinearLayout&gt; &lt;/HorizontalScrollView&gt; &lt;/LinearLayout&gt; </code></pre> <p>I'm then using this code in the ListActivity</p> <pre><code>public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { View v = recordsListView.getChildAt(0); int top = (v == null) ? 0 : v.getTop(); ((ListView)findViewById(R.id.engNameList)).setSelectionFromTop(firstVisibleItem, top); } </code></pre> <p>This should cause the left hand ListView to scroll when the right hand one is scrolled by the user. Unfortunately it doesn't.</p> <p>I've had a bit of a google about and it seems the setSelectionFromTop() function will not work on a ListView that is nested inside more than one layout.</p> <p>If this is the case can anyone suggest a way to get them to scroll together or a different way to set up the layout or a different technique altogether.</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.
 

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