我有一个seekbar
不太合适的习惯.
我希望seekbar
看起来像这样:
但这与我能够得到的一样接近
忽略轻微的着色和尺寸问题,我遇到的问题是绿色progress
尺寸.有没有办法让它比背景小?我试过size
和padding
标记XML
,甚至尝试用夹子摆弄两个长方形gravity
,但没有运气.
这是我的Seekbar
绘画
<?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 android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="@color/fofo_grey" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="@color/signup_green" />
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
而Seekbar中的布局片段
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_below="@+id/textView6"
android:layout_centerHorizontal="true"
android:splitTrack="false"
android:progressDrawable="@drawable/custom_seekbar"
android:thumb="@drawable/thumb_seekbar"
android:max="100"
android:progress="50"
android:indeterminate="false" />
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个基本的自定义Switch
,如下所述.
<Switch
android:id="@+id/availSwitch"
android:layout_width="wrap_content"
android:switchMinWidth="110dp"
android:layout_height="wrap_content"
android:track="@drawable/switch_track"
android:thumb="@drawable/thumb"/>
Run Code Online (Sandbox Code Playgroud)
这@drawable/thumb
是一个简单的PNG,工作正常.
的@drawable/switch_track
定义如下.@drawable/trackon
并且@drawable/trackoff
是PNG的.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/trackoff" />
<item android:state_checked="true" android:drawable="@drawable/trackon" />
<item android:drawable="@drawable/trackoff" />
</selector>
Run Code Online (Sandbox Code Playgroud)
这个开关在大多数情况下看起来和工作原理一样,但是有一些方法可以在用户拖动时拇指移过轨道来"动画"轨道吗?在已检查和未检查之间淡入淡出,或者最好在拇指后面"改变".
当前行为如下所示.