• 自定义SeekBar的使用


    一、seekbar是进度条,可以使用系统的,也可以自己定义,下面我们将自己定义一个seekbar。

    1.自定义滑条,包括对背景,第一进度,第二进度的设置,通过一个xml来实现,在drawable下创建seekbar.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/seek_bg">
        </item>
        <item
            android:id="@android:id/progress"
            android:drawable="@drawable/progress">
        </item>
    
        <item
            android:id="@android:id/secondaryProgress"
            android:drawable="@drawable/secprogress">
        </item>
    
    
    </layer-list>

    2.自定义滑块,包括按压和未按压的样式设置,也通过xml来实现,在drawable下创建selector_thumb.xml文件。

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_pressed="true" android:drawable="@drawable/thumb_press"></item>
        <item  android:drawable="@drawable/thumb"></item>
    
    </selector>
                     

    3.样式展示,通过seekbar两个属性android:thumb="@drawable/thumb",android:progressDrawable="@drawable/seekbarbackground"来设置

    <RelativeLayout xmlns: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"
        tools:context="${relativePackage}.${activityClass}" >
    
        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="自定义seekbar"
            android:textColor="@android:color/holo_purple"
            android:textSize="20sp" />
    
        <SeekBar
            android:id="@+id/sb"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/tv"
            android:layout_marginTop="62dp"
            android:progressDrawable="@drawable/seekbar"
            android:thumb="@drawable/selector_thumb" />
    
    </RelativeLayout>

    4.效果图

  • 相关阅读:
    opengl学习
    同步、异步、多线程与事件型综述
    Javascript异步编程的4种方法
    ASP.NET(C#) GridView (编辑、删除、更新、取消)
    浅析五大ASP.NET数据控件
    用 Eclipse 开发 Android 应用程序
    [C# 网络编程系列]专题十:实现简单的邮件收发器
    [C# 网络编程系列]专题九:实现类似QQ的即时通信程序
    [C# 网络编程系列]专题七:UDP编程补充——UDP广播程序的实现
    [C# 网络编程系列]专题六:UDP编程
  • 原文地址:https://www.cnblogs.com/huipengbo/p/6099277.html
Copyright © 2020-2023  润新知