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

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


  • 2019-11-18 23:18:49

    spring boot中读取配置信息一

    首先我们都知道一个常识,那就是每个人都有自己的年龄,比如我们现在的业务需求是查询所有年龄大于20的人的相关信息,如果我们选择通过配置文件来配置这个值为20的常量的话,我们该如何配置和如何从配置文件中获取这个值呢?,application.yml的内容如下(注意 “age:“ 和 “20“ 之间需要一个空格,yml的语法 ):

  • 2019-11-19 01:20:18

    java8 forEach、filter、map

    filter()、findAny()、orElse()配合使用,可以根据条件获取某个元素,如果没有返回指定的值。

  • 2019-11-19 01:24:01

    使用JAVA8 filter对List多条件筛选

    记录项目开发的过程中遇到的一些问题及解决方法,由于公司操作数据库都是统一使用工具生成的存在一些多表查询模糊查询,这些操作只能在集合方面下手了,比如发送邮件记录方面查询,对用户的名字及邮件模糊检索 年龄匹配查询。

  • 2019-11-21 18:13:08

    如何在vue单页应用中使用百度地图

    百度开发者平台已经封装了基于vue的地图组件,详细使用,请参考官网: https://dafrok.github.io/vue-baidu-map/#/zh/start/installation 网上有一些是直接在index.html页面全部引用的,本人强烈反对此种使用方式,因为我们项目是组件化的单页应用,强行引入多页应用的开发方式,会破坏整个项目的框架,严重影响性能。有些甚至还在vue单页应用中引入jquery,感觉这都是一些反人类的骚操作,不到万不得已,不建议使用。