【问题标题】:How can I change the width/thickness of a scrollbar?如何更改滚动条的宽度/厚度?
【发布时间】:2014-01-13 23:19:13
【问题描述】:

目前这是我的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>

这是我的 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" >

这是它给我的滚动条。挺好的,就是太厚太明显了。在这个屏幕截图中,它可能看起来并不厚,但确实如此。

我可以设置 ScrollView 属性来调整滚动条的宽度/厚度吗?或者我可以在渐变中添加一个属性吗?

【问题讨论】:

  • 你试过减小半径的大小吗?
  • @GrIsHu 半径决定了滚动条顶部和底部的圆度。不是滚动条的宽度。但是是的,无论如何我都试过了。
  • 你可能想看看this

标签: android scrollbar android-scrollview android-scrollbar


【解决方案1】:

将以下属性添加到您的布局中

android:scrollbarSize="50dip"

【讨论】:

    【解决方案2】:

    查看ScrollViewandroid:scrollbarSize="" 属性。

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

    【讨论】:

    • 完美的尺寸,甚至哈哈。我在另一篇文章的评论中问了这个问题,Dehan 说如果我发布问题他会回答。我会接受他的,但我会浏览你以前的问题/答案并给你一些投票。谢谢。
    • @mikeyaworski 真的很高兴帮助你......但不要因为这个答案而支持我的其他答案......(真的我不喜欢那样)如果它帮助你,您可以对此表示赞同。谢谢你
    • 当然,只是想在应得的地方传递声誉。
    【解决方案3】:

    为了使列表视图中的相同类型的滚动条非常容易和多次使用,在 style.xml 和 value 文件夹中的 color.xml 中用作样式和颜色。

    即在 Android Studio 中:

    Project_Name/app/main/res/values

    以及

    中的代码

    style.xml

     <resources>    
       <style name="mScrollBar">
         <item name="android:scrollbarSize">1dp</item>
         <item name="android:scrollbarThumbVertical">@color/base_color</item>
       </style>
     </resources>
    

    在 color.xml 中

     <?xml version="1.0" encoding="utf-8"?>
     <resources>
         <color name="Salmon">#FA8072</color>
     </resources>
    

    【讨论】:

      猜你喜欢
      • 2011-06-03
      • 2016-11-24
      • 2011-02-03
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多