0

我有一个带有滚动条的列表视图。我希望滚动条位于右侧列表项的顶部,但右侧的边距很小。这样滚动条会略微缩进,并且不会靠在列表视图的右侧。

我正在使用<item name="android:scrollbarStyle">insideOverlay</item>并为我的android:scrollbarThumbVertical. 对于我来说android:scrollbarTrackVertical,我只是将其设置为完全透明的颜色。

我尝试在列表视图中添加一个android:layout_marginRightandroid:paddingRight,但这使得列表视图项目没有延伸到滚动条之外。我想要的是列表视图项位于 scorllbar 下方并在另一侧略微可见。

有什么我想念的吗?我可以发布更多代码,但我想让它简单上手,但如果有更多帮助,请告诉我。

谢谢!

编辑:以防万一它有帮助,这里有更多代码:

<RelativeLayout
     android:id="@+id/mainRL"
     android:layout_width="0dp"
     android:layout_height="match_parent"
     android:layout_weight="1">
     <ListView
         android:id="@+id/mainLV"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         style="@style/scrollbar_shape_style">
     </ListView>
</RelativeLayout>

<style name="scrollbar_shape_style">
    <item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
    <item name="android:scrollbars">vertical</item>
    <item name="android:fadeScrollbars">true</item>
    <item name="android:scrollbarThumbVertical">@drawable/scrollbar_vertical_thumb</item>
    <item name="android:scrollbarTrackVertical">@color/fully_transparent</item>
    <item name="android:scrollbarSize">12dp</item>
    <item name="android:scrollbarFadeDuration">@integer/fade_ms</item>
    <item name="android:scrollbarDefaultDelayBeforeFade">@integer/ms_to_fade</item>
    <item name="android:scrollbarStyle">insideOverlay</item>
</style>

编辑2:我尝试了以下答案:如何从ListView的右边缘设置垂直滚动条的边距?(顺便说一句,顶部的图像是我的目标)并且该解决方案不起作用。它也只是移动了我的列表视图项目,它不会使滚动条插入更大。

4

1 回答 1

1

我最终改变了我的drawable。这是该代码:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape>
        <gradient
            android:angle="0"
            android:endColor="@color/primary_dark"
            android:startColor="@color/primary_neutral" />
        <corners android:radius="6dp" />

        <stroke
            android:width="16dp"
            android:color="@color/fully_transparent" />
    </shape>
</item>
</layer-list>

然后,我改为<item name="android:scrollbarSize">12dp</item>24dp。这导致了一个 8dp 宽和偏移 16dp 的条形图。

于 2014-12-18T16:16:43.867 回答