【问题标题】:Android listview scrollbar on top of list items列表项顶部的Android listview滚动条
【发布时间】:2015-02-17 09:39:15
【问题描述】:

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

我正在使用<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: 我尝试了来自How to set margin for Vertical Scrollbar from the right edge in ListView? 的答案(顺便说一句,顶部的图像是我的目标)并且该解决方案不起作用。它也只是移动了我的列表视图项,它不会使滚动条插入更大。

【问题讨论】:

    标签: android android-listview android-scrollbar


    【解决方案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>
    

    然后,我将&lt;item name="android:scrollbarSize"&gt;12dp&lt;/item&gt; 更改为 24dp。这导致了一个 8dp 宽和 16dp 偏移量的条形图。

    【讨论】:

      猜你喜欢
      • 2011-02-22
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多