先看效果
看到网上的博客各种自定义SeekBar,又是整onMeasure,又是旋转平移的,只能说low爆了。
下面最简洁垂直Seekbar,直接布局文件写就OK。
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/volume_dialog"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:clipChildren="true"
android:orientation="vertical">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="300dp"
android:background="@drawable/volume_bg_shape">
<SeekBar
android:id="@+id/mSeekBar"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:rotation="-90" />
</FrameLayout>
</LinearLayout>
这就完了,是不是不敢相信!!!
通过 clipChildren 完美解决,该Idea并不是本人想到的,只是Android源码中 SystemUI 音量条的实现给了我启示。