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

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


  • 2017-04-12 10:52:35

    最全面的Android Webview详解

    现在很多App里都内置了Web网页(Hyprid App),比如说很多电商平台,淘宝、京东、聚划算等等,如下图

  • 2017-04-12 11:22:43

    WebView你真的熟悉吗?看了才知道

    在Android手机中内置了一款高性能webkit内核浏览器,在SDK中封装为一个叫做WebView组件。下面总结一下使用webview遇到的那些事、那些坑。

  • 2017-04-12 11:28:14

    史上最全webview详解

    WebView在现在的项目中使用的频率应该还是非常高的。 我个人总觉得HTML5是一种趋势。找了一些东西,在此总结。 本篇最后有一个非常不错 的 Html5Activity 加载类,不想看的可以直接跳下载。

  • 2017-04-12 23:11:59

    Android Studio签名打包的两种方式

    给我们自己开发的app签名,就代表着我自己的版权,以后要进行升级,也必须要使用相同的签名才行。签名就代表着自己的身份(即keystore),多个app可以使用同一个签名。

  • 2017-04-13 10:57:08

    webstorm 怎么关闭jshint

    You need to configure the inspections in Settings/Editor/Inspections, then in the list on the right, find JavaScript/JavaScript validity issues. That worked for me to remove the Chai warnings. (I am using the WebStorm 11 EAP at the moment.)

  • 2017-04-13 14:11:14

    MySQL中的describe关键字

    今天写代码的时候,有一个类的数据始终不能插入,老是提示在You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'describe, picPath1, picPath2, picPath3, picPath4, picPath5, agentId, belongStore' at line 1。因为用的是SSH进行插入,所以SQL语句不用自己写,检查了每个字段也没写错。

  • 2017-04-15 13:34:08

    Android官方技术文档翻译——清单合并

    一般情况下,有三种类型的清单文件需要合并成一个最终的应用程序清单,这里按照优先级顺序列出: Product flavors 和构建类型所指定的清单文件。 应用程序的主清单文件。 类库的清单文件。