Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing Android Fast Scroll Bar on ListViews to draw within padding

I am interested in creating a screen composed of a transparent header and a listview that scrolls behind the header. I have this working with one flaw; the FAST scroll bar also draws underneath header.

For some reason, the fastscrollbar doesn't seem to respect the scrollbarStyle applied to the list view. You'll notice in the image below that the normal scroll bar works fine, but the powerscroll bar is behind the transparent header.

FastScrollBar and NormalScrollBar example

Unfortunately the listviews I am using will often have hundreds of items, so the fastscrollbar is a necessity. Is there some way to set the "fastscrollStyle" that is not documented? I am open to any suggestions! Thank you.

Here is the layout XML for reference:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

    <ListView
        android:id="@+id/myListView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clipToPadding="false"
        android:fastScrollEnabled="true"
        android:scrollbars="vertical"
        android:scrollbarStyle="insideOverlay"
        android:paddingTop="50dp"/>

    <TextView android:text="My Header"
              android:gravity="center"
              android:background="#8fff0000"
              android:layout_width="fill_parent"
              android:layout_height="50dp"/>
</RelativeLayout>

This was fixed in KitKat for ListView, however GridView still appears to exhibit this problem. Google?

like image 730
supereee Avatar asked Aug 02 '13 17:08

supereee


1 Answers

The best solution is to separate your listview from the other layouts, where the main relativelayout view is the parent and other layouts are the children.

EX.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
     <RelativeLayout
              android:id"@+id/layoutHeader"
              android:layout_width="fill_parent"
              android:layout_height="50dp"
              android:layout_alignParentTop="true">

              <TextView android:text="My Header"
                        android:gravity="center"
                       android:background="#8fff0000"
                       android:layout_width="fill_parent"
                       android:layout_height="50dp"/>
    </RelativeLayout>

    <RelativeLayout
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="+id/layoutHeader">
    <ListView
        android:id="@+id/myListView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clipToPadding="false"
        android:fastScrollEnabled="true"
        android:scrollbars="vertical"
        android:scrollbarStyle="insideOverlay"
        android:paddingTop="50dp"/>
    </RelativeLayout>
</RelativeLayout>
like image 66
MahmoudA Avatar answered Oct 02 '22 15:10

MahmoudA