【问题标题】:How to set margin for Vertical Scrollbar from the right edge in ListView?如何从 ListView 的右边缘设置垂直滚动条的边距?
【发布时间】:2011-08-24 02:53:21
【问题描述】:

对于安卓平台:

我需要在列表视图的垂直滚动条的右侧放置边距(它是自定义的)。请看附图。默认滚动条粘在列表视图的最右侧。

需要你的手。谢谢。

【问题讨论】:

  • 这是用于什么平台/GUI 框架的?其中很多都有垂直滚动条和 ListViews。
  • 这适用于 Android 平台 2.1 及以上版本。

标签: android listview scrollbar margin


【解决方案1】:

如果您关心您的设计并希望在全球范围内应用该样式,请使用此。


res/values/styles.xml

<item name="android:scrollbarThumbVertical">@drawable/scrollbar</item>

res/drawable/scrollbar.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:right="4dp"> <!-- Your Margin -->
        <shape>
            <solid android:color="@color/red500" /> <!-- Your Color -->
            <corners android:radius="2dp" /> <!-- Your Radius -->
            <size android:width="4dp" /> <!-- Your Width -->
        </shape>
    </item>
</layer-list>

所有其他答案都是由开发人员创建的,而不是像我这样的设计师。

结果

【讨论】:

  • 这就是我想要的! Tnx 迈克尔!
  • 很抱歉,我只能投一个赞成票。这个答案值得 100。
【解决方案2】:

Viewandroid:scrollbarStyle 属性上参考documentation。您可能想要使用的样式是insideOverlay(与android:paddingRight 结合使用)。

类似

<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
    android:paddingRight="50dip">
    <ListView
        android:id="@+id/scrollable_table" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarStyle="insideOverlay">
    .
    .
    .

【讨论】:

  • 为什么不使用包装器直接在ListView中进行填充?
  • @Michael 的回答要好得多。请查看并考虑更改接受的答案。
  • 注意:如果你需要相反的(让滚动条向右移动)并且有paddingRightclipToPadding = false,使用outsideOverlay
【解决方案3】:

尝试启用快速滚动,它大部分时间都可以完成这项工作:

<ListView
    android:id="@+id/chapter_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fastScrollEnabled="true"/>

【讨论】:

  • 这没有回答问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-12
  • 2011-08-16
  • 1970-01-01
  • 2011-03-31
相关资源
最近更新 更多