您的位置:首页 > 产品设计 > UI/UE

Android SeekBar自定义UI

2012-02-24 16:59 351 查看
1.制作好相应的图片,放入res/drawable-xxxx文件夹下

2、在 /res/drawable/ 下新建两个文件:seek_img.xml thumb.xml

seek_img.xml

<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><!-- 背景图 -->  <item    android:id="@+android:id/background"    android:drawable="@drawable/total"/>    <!--全部能量图  -->  <item    android:id="@+android:id/SecondaryProgress"    android:drawable="@drawable/total"/>    <!-- 进和能量图 -->  <item    android:id="@+android:id/progress"    android:drawable="@drawable/part"/></layer-list>


thumb.xml

<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android">               <!-- 按下状态 -->        <item               android:state_pressed="true"android:state_focused="true"             android:drawable="@drawable/point"/>    <!-- 普通无焦点状态 -->        <item        android:state_focused="false"              android:state_pressed="false"            android:drawable="@drawable/point"/></selector>


3、定义好上面两个xml后,就可以在 /res/layout/main.xml中调用它们了。

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <SeekBar        android:id="@+id/sBar"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_centerInParent="true"        android:minHeight="5dip"        android:maxHeight="5dip"        android:progressDrawable="@drawable/seek_img"        android:thumb="@drawable/thumb"/></LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: