Android 如何更改滚动条的宽度/厚度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20782499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I change the width/thickness of a scrollbar?
提问by Michael Yaworski
Currently this is my scrollbar.xml
file:
目前这是我的scrollbar.xml
文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="45"
android:centerColor="@color/blue"
android:endColor="@color/blue"
android:startColor="@color/blue" />
<corners android:radius="8dp" />
</shape>
And this is my ScrollView:
这是我的滚动视图:
<ScrollView
android:id="@+id/scrollView1"
android:scrollbarThumbVertical="@drawable/scrollbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/btnBack" >
This is the scrollbar it gives me. It's good, except it's too thick and obvious. It may not look thick in this screenshot, but it really is.
这是它给我的滚动条。很好,只是它太厚太明显了。在此屏幕截图中它可能看起来不厚,但确实如此。
Am I able to set a ScrollView property to adjust the width/thickness of the scrollbar? Or can I put a property in my gradient?
我可以设置 ScrollView 属性来调整滚动条的宽度/厚度吗?或者我可以在我的渐变中放置一个属性吗?
回答by Dehan Wjiesekara
add the following property to your layout
将以下属性添加到您的布局
android:scrollbarSize="50dip"
回答by Gopal Gopi
see the android:scrollbarSize=""
attribute of ScrollView
.
参见 的android:scrollbarSize=""
属性ScrollView
。
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/btnBack"
android:scrollbarSize="4dp"
android:scrollbarThumbVertical="@drawable/scrollbar" >
回答by Arunendra
For making very easy and using many times, same type of scrollbar in list view, use as a style and color in style.xml and color.xml in values folder.
为了非常容易和多次使用,列表视图中的相同类型的滚动条,在值文件夹中的 style.xml 和 color.xml 中用作样式和颜色。
i.e. in Android Studio :
即在 Android Studio 中:
Project_Name/app/main/res/values
Project_Name/app/main/res/values
and the code in
和代码
style.xml
样式文件
<resources>
<style name="mScrollBar">
<item name="android:scrollbarSize">1dp</item>
<item name="android:scrollbarThumbVertical">@color/base_color</item>
</style>
</resources>
in color.xml
在 color.xml 中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Salmon">#FA8072</color>
</resources>