【问题标题】:How to show tick marks for Discrete Slider?如何显示离散滑块的刻度线?
【发布时间】:2016-05-24 01:53:50
【问题描述】:

我正在尝试设置类似Material Design Guidelines 中标记为Discrete Slider - Click(带有小刻度标记)的搜索栏/滑块。我无法弄清楚让标记出现的神奇咒语,有人知道怎么做吗?

我有一个有 5 个位置 (0-4) 的搜索栏

<SeekBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="4" />

【问题讨论】:

    标签: android material-design seekbar material-components-android android-slider


    【解决方案1】:

    现在您可以在材质组件库中使用Slider。
    刻度线默认显示在离散滑块中。

        <com.google.android.material.slider.Slider
            android:valueFrom="0"
            android:valueTo="10"
            android:stepSize="1"
            .../>
    

    【讨论】:

      【解决方案2】:

      使用样式属性添加刻度线:

      <SeekBar
          android:id="@+id/seekBar"
          style="@style/Widget.AppCompat.SeekBar.Discrete"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:max="10"
          />
      

      或者通过设置tickMark drawable来手动添加:

      <SeekBar
          android:id="@+id/seekBar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:max="10"
          android:tickMark="@drawable/tickmark"
          />
      

      tickmark.xml

      <shape xmlns:android="http://schemas.android.com/apk/res/android"
             android:shape="oval">
          <size android:width="4dp"
                android:height="4dp"/>
          <solid android:color="@android:color/white"/>
      </shape>
      

      【讨论】:

      • 啊,这似乎是最近在 24.x.x 支持库中添加的(在 23.4.0 中似乎不可用)
      • @NameSpace 我没有在搜索栏上看到股票指示器,你能帮帮我吗?
      • @NameSpace 搜索栏如何知道放置刻度线的步长
      • 它从“max”值知道它。 max 为 10 时,会将 SeekBar 分成 10 段,并在每段之间打勾。
      猜你喜欢
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多