Android - xml可绘制的形状大小设置为填充父级?

时间:2015-07-11 17:05:43

标签: android xml android-layout android-drawable fastscroll

我正在使用快速滚动条。我想在旧设备上使用Android 5.1风格的快速滚动条(我在Android 5.0.2,API 21上测试)。这是我到目前为止所得到的图片。 (由于声誉系统我不能发布照片(我是新来的),所以它是我的Google照片的链接。)

https://goo.gl/photos/YihnpUN3SfjLjjB8A

这是我的问题:我希望滚动条轨道(灰色部分)占据屏幕的整个高度(更确切地说是内容的整个高度)。现在它从操作栏下面几个像素开始,并在导航栏上方几个像素处结束 - 我希望它从操作栏正下方开始,并在导航栏的正上方结束。

这是我的代码实现:

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>

我正在使用一个片段列表:

片段布局文件

<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>

我认为正在发生的事情是我只是改变了快速滚动条的“主题”。由于我使用的是API 21,因此库存滚动条看起来不同(它只是一条带有较小拇指的细线 - https://goo.gl/photos/T15JVGgpisqqYSd26)。我设法让拇指高48dp,宽8dp,就像它应该的那样。但是,我无法改变赛道的高度。我想将它设置为类似“fill_parent”的东西,但我不能 - 唯一允许的单位是px,dp,sp,in和mm。有没有简单的解决方法,或者我是否需要深入研究fastscroll实现?

还有一个问题:有人能告诉我快速滚动轨道的正确颜色吗?我目前正在使用#21000000

感谢。

0 个答案:

没有答案