How to set margin for Vertical Scrollbar from the right edge in ListView?

我只是一个虾纸丫 提交于 2019-12-12 07:11:23

问题


For Android Platform:

I need to put margin on right side of the vertical scrollbar in listview (it is customized). Please see the attached image. Default scrollbar sticks to the extream right side of the listview.

Need your hand. Thanks.


回答1:


Refer to documentation on android:scrollbarStyle attribute of View. The style you probably want to use is insideOverlay (in conjunction with android:paddingRight).

Something like

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



回答2:


If you care about your design and want to apply the style globally use this.


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>

All the other answers were created by developers, not designers like myself.

Result




回答3:


Try enabling fast scroll, it does the job most of the time:

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


来源:https://stackoverflow.com/questions/5978430/how-to-set-margin-for-vertical-scrollbar-from-the-right-edge-in-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!