如何为包含位图的SeekBar的进度状态添加圆角?
此进度位图是一个PNG文件,其中包含要重复的模式,这就是为什么我不能在此状态下使用九个补丁的原因。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<nine-patch android:src="@drawable/background"/>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<nine-patch android:src="@drawable/secondary_progress"/>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<bitmap android:src="@drawable/progress" android:tileMode="repeat"/>
</clip>
</item>
</layer-list>
期望的样子:
答案 0 :(得分:0)
尝试此测试代码(在Activity#onCreate
中添加)并修改sb.xml
以满足您的需求:
SeekBar sb = new SeekBar(this);
setContentView(sb, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 128));
LayerDrawable ld = (LayerDrawable) getResources().getDrawable(R.drawable.sb);
float[] radii = {
32, 32, 32, 32, 32, 32, 32, 32,
};
ShapeDrawable sd = new ShapeDrawable(new RoundRectShape(radii, null, null));
sd.setShaderFactory(new ShapeDrawable.ShaderFactory() {
@Override
public Shader resize(int width, int height) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.chrome);
return new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
}
});
Drawable cd = new ClipDrawable(sd, Gravity.LEFT, ClipDrawable.HORIZONTAL);
ld.setDrawableByLayerId(android.R.id.progress, cd);
sb.setProgressDrawable(ld);
RES /抽拉/ sb.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>
<solid android:color="#0a0"/>
<corners android:radius="32px"/>
</shape>
</item>
<item android:id="@android:id/progress" android:drawable="@android:color/transparent">
</item>
</layer-list>