Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the simplest code to illustrate the main idea:</p> <pre><code>listView.setOnScrollListener(new OnScrollListener() { ViewGroup mainView = (ViewGroup) findViewById(R.id.main); View pinnedView = null; @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem &lt; PINNED_ITEM) { mainView.removeView(pinnedView); pinnedView = null; } else if (pinnedView == null) { pinnedView = adapter.getView(PINNED_ITEM, null, view); pinnedView.setBackgroundColor(0xFF000000); mainView.addView(pinnedView); } } @Override public void onScrollStateChanged(AbsListView view, int scrollState) {} }); </code></pre> <p>I have a <code>FrameLayout</code> which contains nothing but my <code>ListView</code>:</p> <pre><code>&lt;FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/main" &gt; &lt;ListView android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;/FrameLayout&gt; </code></pre> <p><code>PINNED_ITEM</code> is the position of your item (for example, <code>PINNED_ITEM = 2</code>). This layout acts as an overlay for the list. The <code>ScrollListener</code> tracks the current visible items and if it detects that an item should be pinned, it adds it to the layout and removes it otherwise.</p> <p>The line <code>pinnedView.setBackgroundColor(0xFF000000);</code> is needed to set an opaque background for the item. The item will be transparent if you don't do this. You can tweak the background according to your needs (for example, you can use a background from your current theme attribute).</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. This table or related slice is empty.
    1. VO
      singulars
      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