android自訂實現自己需要seekbar

來源:互聯網
上載者:User

系統seekbar不好看,我們可以自訂來滿足我們的需求,主要就是xml的配置activity使用的xml:      有2個seek bar,一個通過style設定,一個直接用xml,原理一樣的<LinearLayout 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"     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:<style name="player_progressBarStyleHorizontal">        <item name="android:paddingLeft">10.0dip</item>            <item name="android:paddingRight">10.0dip</item>        <item name="android:maxHeight">8.0dip</item>        <item name="android:progressDrawable">@drawable/player_seekbar_horizontal</item>        <item name="android:minHeight">8.0dip</item>        <item name="android:thumb">@drawable/player_seek_thumb</item>        <item name="android:thumbOffset">0.0dip</item>        <item name="android:layout_centerHorizontal">true</item>        <item name="android:layout_centerVertical">true</item>    </style> player_seekbar_horizontal.xml:   定義滑塊<?xml version="1.0" encoding="utf-8"?><selector  xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_window_focused="true" android:state_pressed="true" android:drawable="@drawable/player_progress_thumb_pressed" />    <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/player_progress_thumb_pressed" />    <item android:state_window_focused="true" android:state_selected="true" android:drawable="@drawable/player_progress_thumb_pressed" />    <item android:drawable="@drawable/player_progress_thumb" /></selector> @drawable/player_seek_thumb:  背景<?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/player_progress_background" />    <item android:id="@*android:id/secondaryProgress" android:drawable="@drawable/player_progress_second" />    <item android:id="@*android:id/progress" android:drawable="@drawable/player_progress" /></layer-list>  bar_bg.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"><shape><corners android:radius="10dip" /><gradient android:startColor="#ffffffff"android:centerColor="#ff000000" android:endColor="#ff808A87"android:centerY="0.45" android:angle="270" /></shape></item> <item android:id="@android:id/progress"><clip><shape><corners android:radius="10dip" /><gradient android:startColor="#ffffffff"android:centerColor="#ffFFFF00" android:endColor="#ffAABD00"android:centerY="0.45" android:angle="270" /></shape></clip></item></layer-list>    bar_selector.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/player_progress_thumb_pressed"></item>    <item android:drawable="@drawable/player_progress_thumb"></item> </selector>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.