SeekBar的高度及thumb圆点显示不完全

2019-06-24 06:18:52


参考链接  SeekBar的高度及thumb圆点显示不完全


直接进入正题,请看以下代码:


<SeekBar

    android:id="@+id/seekbar_def"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:layout_below="@+id/distance"

    android:max="25"

    android:maxHeight="@dimen/x5"

    android:minHeight="@dimen/x5"

    android:progress="0"

    android:progressDrawable="@drawable/selector_seekbar_bg"

    android:thumb="@drawable/shape_point_circular"

    android:thumbOffset="0dip" />

1

2

3

4

5

6

7

8

9

10

11

12

控制SeekBar条的高度在于这三个属性


android:layout_height="wrap_content"

android:maxHeight="@dimen/x5"

android:minHeight="@dimen/x5"

1

2

3

maxHeight和minHeight越大,则条的高度越大。


至于圆点,也就是thumb的大小,如果你使用的是图片,那么你的图片有多大,在这种属性设置下都会显示完全,但是无法控制圆点大小。但是我发现如果使用shape来绘制圆点的话,是有一个属性来控制圆点大小。


android:thumb="@drawable/shape_point_circular"

1

这个属性用来自定义圆点,shape_point_circular的内容如下:


<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android" >


    <!-- 绿色圆点-->


    <solid android:color="#6fb737" />


    <corners android:radius="8dp"/>


    <size

        android:height="15dp"

        android:width="15dp"/>


</shape>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

其中size内的height和width可以用来控制画出的圆点的大小。


顺便记录一下这个控件的其他参数


android:progressDrawable="@drawable/selector_seekbar_bg"

1

这个属性用来自定义条的样式,我都是用绘画的方式实现的,以下是selector_seekbar_bg的内容:


<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >


    <item

        android:id="@android:id/background">

        <shape android:shape="rectangle" >

            <solid android:color="@color/gray" />


            <corners android:radius="@dimen/x5" />

        </shape>

    </item>

    <item

        android:id="@android:id/progress">

        <clip>

            <shape android:shape="rectangle" >

                <corners android:radius="@dimen/x5" />


                <solid android:color="@color/title_color" />

            </shape>

        </clip>

    </item>


</layer-list>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

android:max="25"

1

整个控件的最大值,可以理解为SeekBar的圆点滚动25下即滚动到最右边。


android:progress="0"

1

表示默认值,即圆点初始位置。


android:thumbOffset="0dip"

1

这个属性需要注意咯,当你不设置这个属性的话,你的圆点在最左边的时候是会显示不全的。


  • 2020-11-24 19:18:43

    nuxtjs打成用于webview的相对路径

    路径为绝对路径,当项目的域名为二级域名的时候,就不能打包为这绝对路径了。 nuxt不同于vue项目,思索了许久,终于找到了配置的地方

  • 2020-11-24 23:22:59

    eruda,移动端网页调试神器

    webapp或者移动端网页需要嵌入到app时候,尤其是在APP内置的webView上加载我们的页面,想要查看手机浏览器信息是非常困难的事,当出现问题的时候,你又不能查看日志,一般会连接本地测试环境,然后在alert来打印日志

  • 2020-11-30 09:04:02

    js中set和get方法

    1. get和set是方法,因为是方法,所以可以进行判断 2. get一般是要返回的;而set是设置,不用返回 3. 如果调用对象内部的属性约定的命名方式是变量名前加_

  • 2020-12-01 16:10:12

    IntelliJ IDEA之代理配置 anyproxy

    网络号,真是太爽了,真的,如果又了好的网络,开发真是事半功倍,所以,大家开发前,一定要把自己的网络给整好。 会给你节省不少时间呢。

  • 2020-12-01 16:14:54

    HTTP状态码429的含义

    发生429是服务器接口并发太多引起的,可根据代码进行修改,放开限制次数

  • 2020-12-01 16:19:26

    vue中动画分布解析

    enter, enter-active, enter-active-to, (开始 进入阶段的)第1帧 属性值,到 (默认属性值 的过渡阶段),移除enter动画, leave, leave-active, leave-active-to (开始 离开 阶段的)第1帧 默认属性值,到 (属性值 的过渡阶段),移除leave动画