InsetDrawable详解

今天要改一个播放器的UI,改到下方的播放进度条的时候,本来打算自定义一个来着,但是看着界面也不复杂,就想着用系统提供的控件来试试,主要就是seekBar的样式,进度的颜色是渐变的,进度的滑块是个白色圆形。下面主要讲的是系统控件的各个属性,许多时候仅仅依靠系统控件就可以实现好多效果了:

<SeekBar  
        android:id="@+id/progressBar1"  
        android:layout_width="match_parent"  
        android:layout_height="20dp"  
        android:progress="50"
        android:paddingLeft="5dp" 
        android:paddingRight="5dp"
        <!-- 通过这个属性来给seekBar滑块换图片 -->
        android:thumb="@drawable/kids_play_progress_thumb"
        android:thumbOffset="0dp"
        <!-- 通过这个属性来给seekBar来设置背景色,进度条颜色以及二级进度颜色 -->
        android:progressDrawable="@drawable/kids_play_progress" /> 

主要来讲讲android:progressDrawable这个属性,在drawable文件夹内新建xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/background" android:drawable="@drawable/background">        
    </item>
    <item android:id="@android:id/progress"      android:drawable="@drawable/progress">
    </item>
</layer-list>

这样就可以实现效果了,但是有个问题,就是滑块和进度条的颜色是一样高度的,效果图是要突出滑块的,也就是滑块要比进度条上下突出一点,这个时候就要引出今天的主角了InsetDrawable,在上方的item中可以用标签,inset标签有这些属性,如果用的图片,在drawable中设置就OK,如果用shape就在首尾标签内加上shape,

android:drawable
android:insetBottom  
android:insetLeft    
android:insetRight   
android:insetTop     
android:visible

修改后的layer-list如下:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/background">
        <inset
            android:insetBottom="5dp"
            android:insetTop="5dp" >
            <shape>
                <gradient
                    android:angle="0"
                    android:endColor="#99ffffff"
                    android:startColor="#99ffffff" />
                <stroke android:color="#99ffffff" android:width="1px" />
            </shape>
        </inset>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <inset
                android:insetBottom="5dp"
                android:insetTop="5dp" >
                <shape>
                    <gradient
                        android:angle="0"
                        android:endColor="#8eabff"
                        android:startColor="#b5c8ff" />
                    <stroke android:color="#8eabff" android:width="1px" />
                </shape>
            </inset>
        </clip>
    </item>
</layer-list>

这个inset标签其实就是来设置这个图片内缩,只是内容内缩,这样可以实现进度条比滑块窄。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值