android自定义实现自己需要seekbar

系统seekbar不好看,我们可以自定义来满足我们的需求,主要就是xml的配置

activity使用的xml:      有2个seek bar,一个通过style设置,一个直接用xml,原理一样的

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent" 

    android:background="#ffffff"

    android:orientation="vertical"

    android:gravity="center"

    >


    <SeekBar

        android:id="@+id/seekBar"

        style="@style/player_progressBarStyleHorizontal"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_gravity="center_vertical"/>

    

    

    <SeekBar

        android:maxHeight="8dp"

        android:thumbOffset="0dp"

        android:layout_gravity="center_vertical"

        android:paddingLeft="30dp"

        android:paddingRight="30dp"

       android:progressDrawable="@drawable/bar_bg"

       android:thumb="@drawable/bar_selector"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

       />


</LinearLayout>




style:

<stylename="player_progressBarStyleHorizontal">

        <itemname="android:paddingLeft">10.0dip</item>    

        <itemname="android:paddingRight">10.0dip</item>

        <itemname="android:maxHeight">8.0dip</item>

        <itemname="android:progressDrawable">@drawable/player_seekbar_horizontal</item>

        <itemname="android:minHeight">8.0dip</item>

        <itemname="android:thumb">@drawable/player_seek_thumb</item>

        <itemname="android:thumbOffset">0.0dip</item>

        <itemname="android:layout_centerHorizontal">true</item>

        <itemname="android:layout_centerVertical">true</item>

    </style>


player_seekbar_horizontal.xml:  定义滑块

<?xmlversion="1.0"encoding="utf-8"?>

<selector

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

    <itemandroid:state_window_focused="true"android:state_pressed="true"android:drawable="@drawable/player_progress_thumb_pressed"/>

    <itemandroid:state_focused="true"android:state_window_focused="true"android:drawable="@drawable/player_progress_thumb_pressed"/>

    <itemandroid:state_window_focused="true"android:state_selected="true"android:drawable="@drawable/player_progress_thumb_pressed"/>

    <itemandroid:drawable="@drawable/player_progress_thumb"/>

</selector>


@drawable/player_seek_thumb:  背景

<?xmlversion="1.0"encoding="utf-8"?>

<layer-list

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

    <itemandroid:id="@*android:id/background"android:drawable="@drawable/player_progress_background"/>

    <itemandroid:id="@*android:id/secondaryProgress"android:drawable="@drawable/player_progress_second"/>

    <itemandroid:id="@*android:id/progress"android:drawable="@drawable/player_progress"/>

</layer-list>



bar_bg.xml:

<?xmlversion="1.0"encoding="UTF-8"?>

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


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

<shape>

<cornersandroid:radius="10dip"/>

<gradientandroid:startColor="#ffffffff"

android:centerColor="#ff000000"android:endColor="#ff808A87"

android:centerY="0.45"android:angle="270"/>

</shape>

</item>


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

<clip>

<shape>

<cornersandroid:radius="10dip"/>

<gradientandroid:startColor="#ffffffff"

android:centerColor="#ffFFFF00"android:endColor="#ffAABD00"

android:centerY="0.45"android:angle="270"/>

</shape>

</clip>

</item>

</layer-list>  



bar_selector.xml:

<?xmlversion="1.0"encoding="utf-8"?>

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

    <itemandroid:state_pressed="true"android:drawable="@drawable/player_progress_thumb_pressed"></item>

    <itemandroid:drawable="@drawable/player_progress_thumb"></item>


</selector>

 

本人自己的android 赚钱软件,3分钟可以赚一个Q币,有喜欢的可以看看:下载地址

http://as.baidu.com/a/item?docid=6388638



本人网站,大家多多支持:蝌蚪手机赚钱


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值