【问题标题】:Make Seekbar thumb easier to grab让 Seekbar 拇指更容易抓握
【发布时间】:2017-05-16 13:07:55
【问题描述】:

所以我有一个 SeekBar,但小圆圈拇指的东西有点难以抓住。有没有办法让hitbox变大?我不一定关心图形本身是否有任何不同——我只是希望它可以被抓取。

【问题讨论】:

    标签: android touch seekbar


    【解决方案1】:

    您可以通过更改 Thumb 的大小来自定义搜索栏,由 Andrew 回答。 创建 layered-drawable 形状为占位符 thumb_image.xml

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape>
            <size
                android:height="40dp"
                android:width="40dp" />
    
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>
    <item android:drawable="@drawable/scrubber_control_normal_holo"/>
    </layer-list>
    

    下面的例子显示了结果。

    <SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:thumb="@drawable/thumb_image" />
    

    Thumb 自定义的另一个很好的例子。

    【讨论】:

      【解决方案2】:

      查看这个酷炫的 Seekbar 库 DiscreteSeekBar

      并且可以通过以下方式轻松添加

      <org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:dsb_min="2"
              app:dsb_max="15"
      />
      

      它还具有以下属性。

      dsb_progressColor: color/colorStateList for the progress bar and thumb drawable
      dsb_trackColor: color/colorStateList for the track drawable
      dsb_indicatorTextAppearance: TextAppearance for the bubble indicator
      dsb_indicatorColor: color/colorStateList for the bubble shaped drawable
      dsb_indicatorElevation: related to android:elevation. Will only be used on API level 21+
      dsb_rippleColor: color/colorStateList for the ripple drawable seen when pressing the thumb. (Yes, it does a kind of "ripple" on API levels lower than 21 and a real RippleDrawable for 21+.
      dsb_trackHeight: dimension for the height of the track drawable.
      dsb_scrubberHeight: dimension for the height of the scrubber (selected area) drawable.
      dsb_thumbSize: dimension for the size of the thumb drawable.
      dsb_indicatorSeparation: dimension for the vertical distance from the thumb to the indicator.
      

      库中的其他 SeekBar 组件为these

      【讨论】:

        【解决方案3】:

        您想要一个可嵌入的可绘制资源。这个问题“ShapeDrawable 中的偏移形状”https://stackoverflow.com/a/3674134/3175580 的答案恰好是同一件事,你在问。与其他答案一样,如果它是私有的,您仍然需要复制目标可绘制对象。

        优点(或缺点)在于,它可以准确地显示您将尺寸增加了多少,而不是总尺寸。另外,我认为它可以节省内存,因为使用透明形状将创建该大小的透明位图 (?)。

        【讨论】:

          猜你喜欢
          • 2015-09-26
          • 2015-12-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-12-02
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多