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

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


  • 2018-12-13 22:48:48

    Android MultiDex实践:如何绕过那些坑?

    MultiDex, 顾名思义,是指多dex实现,大多数App,解压其apk后,一般只有一个classes.dex文件,采用MultiDex的App解压后可以看到有classes.dex,classes2.dex,… classes(N).dex,这样每个dex都可以最大承载65k个方法,很大限度地缓解了单dex方法数限制。

  • 2018-12-14 13:32:18

    解决chrome调试手机模式没有鼠标问题

    F12后,切换到手机模式,方向没有鼠标,这对于调试前端页面来说无疑是一大难题,看不见只能盲点, 以为是浏览器问题,清理缓存,升级浏览器,清除插件等都不好使。 后来查到资料说是显卡问题。果然还真是显卡问题。

  • 2018-12-14 17:12:51

    Android APP适配全面屏手机的技术要点

    全面屏是手机业界对于超高屏占比手机设计的一个宽泛的定义。从字面上解释就是,手机的正面全部都是屏幕,四个边框位置都是采用无边框设计,追求接近100%的屏占比。但受限于目前的技术,还不能做到手机正面屏占比100%的手机。现在业内所说的全面屏手机是指真实屏占比可以达到80%以上,拥有超窄边框设计的手机。

  • 2018-12-14 17:15:50

    Android适配刘海屏沉浸式状态栏的一些坑

    18年简直是刘海元年,所有手机都在跟风刘海屏,甚至每个厂商还有自己的一套适配规范。我的初始需求很简单,就是做一个全屏显示的页面,一般情况下只需要开启Android规范的全屏模式就好:

  • 2018-12-16 12:12:12

    android:windowSoftInputMode属性具体解释

    android:windowSoftInputMode属性一共同拥有9个取值。各自是: stateUnspecified,stateUnchanged。stateHidden,stateAlwaysHidden。stateVisible,stateAlwaysVisible,adjustUnspecified,adjustResize。adjustPan。

  • 2018-12-16 18:14:23

    Android在代码中设置状态栏半透明/全透明

    顶部是有文字,小图标等,如果直接用透明半透明 状态栏上的东西会与内容重叠(你觉得无所谓也可以直接用上面2部分代码),这样我们就想做成类似支付宝这样的效果: