Android xml drawable shape size set to fill parent?

I am working on a quick scrollbar. I want to use the accelerated scroll bar of Android 5.1 on older devices (I am testing on Android 5.0.2, API 21). Here is a picture of what I still have. (I cannot post photos due to the reputation system (I'm new here), so this is a link to my Google photos.)

https://goo.gl/photos/YihnpUN3SfjLjjB8A

Here is my problem: I want the scrollbar track (gray part) to occupy the entire height of the screen (more precisely, the entire height of the content). Now it starts with a few pixels below the action bar and ends with a few pixels above the navigation bar - and I would like it to start right below the action bar and end right above the navigation bar.

Here is my code implementation:

drawable fastscroll_thumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <layer-list>
            <item android:left="8dp">
                <shape
                    android:tint="?attr/colorControlActivated"
                    android:shape="rectangle">
                    <solid android:color="@color/colorPrimaryDark" />
                    <size
                        android:width="8dp"
                        android:height="48dp" />
                </shape>
            </item>
        </layer-list>
    </item>
    <item>
        <layer-list>
            <item android:left="8dp">
                <shape
                    android:tint="?attr/colorControlNormal"
                    android:shape="rectangle">
                    <solid android:color="@color/colorPrimary" />
                    <size
                        android:width="8dp"
                        android:height="48dp" />
                </shape>
            </item>
        </layer-list>
    </item>
</selector>

drawable fastscroll_track.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item android:left="8dp">
                <shape
                    android:tint="?attr/colorControlNormal"
                    android:shape="rectangle">
                    <solid android:color="@color/fastScrollTrack" />
                    <size android:width="8dp" />
                </shape>
            </item>
        </layer-list>
    </item>
</selector>

I use the snippet for the list:

fragment layout file

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/all_songs_fragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="@android:color/transparent"
        android:drawSelectorOnTop="true"
        android:focusable="true"
        android:clickable="true"
        android:fastScrollEnabled="true" />
</LinearLayout>

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb</item>
        <item name="android:fastScrollTrackDrawable">@drawable/fastscroll_track</item>
    </style>
</resources>

I think I continue by simply changing the "theme" of the fast scrollbar. Since I'm using API 21, the scrollbar looks different (it's just a thin line with a smaller thumb - https://goo.gl/photos/T15JVGgpisqqYSd26 ). I managed to make the thumb at 48dp and 8dp wide, as intended. However, I cannot change the height of the track. I would like to set it as "fill_parent", but I cannot - the only allowed units are px, dp, sp, in and mm. Is there any agile solution, or do I need to delve deeper into the implementation of fastscroll?

: - fastscroll? #21000000.

.

+4

All Articles