Bli*_*aig 9 android android-layout
我有一个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)
小智 15
<?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" />
<stroke android:width="6dp"
android:color="@color/fofo_grey" />
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
只需在seekbar drawable中添加stroke属性即可
管理来解决这个问题.不敢相信我花了这么长时间才想到解决方案......
<clip>
<shape android:shape="rectangle">
<stroke android:color="@color/fofo_grey" android:width="6dp"/>
<corners android:radius="20dp" />
<solid android:color="@color/signup_green" />
</shape>
</clip>
Run Code Online (Sandbox Code Playgroud)
添加了stroke
与背景元素相同的颜色,并调整stroke
width
以实现所需的效果.