我设法创建了一个xml drawable,看起来像这样,它应该是这样的:
代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="line">
<stroke android:color="@color/black"
android:width="3dp" />
<solid android:color="#f000"/>
</shape>
</item>
<item android:top="1dp" android:left="360dp" android:bottom="1dp" android:right="0dp">
<shape android:shape="oval">
<size android:width="15dp"
android:height="15dp"/>
<solid android:color="@color/black"/>
</shape>
</item>
<item android:top="1dp" android:left="246dp" android:bottom="1dp" android:right="114dp">
<shape android:shape="oval">
<size android:width="25dp"
android:height="25dp"/>
<solid android:color="@color/black"/>
</shape>
</item>
<item android:top="1dp" android:left="114dp" android:bottom="1dp" android:right="246dp">
<shape android:shape="oval">
<size android:width="25dp"
android:height="25dp"/>
<solid android:color="@color/black"/>
</shape>
</item>
<item android:top="1dp" android:left="0dp" android:bottom="1dp" android:right="360dp">
<shape android:shape="oval">
<size android:width="25dp"
android:height="25dp"/>
<solid android:color="@color/black"/>
</shape>
</item>
</layer-list>
然后我将它应用到我的SeekBar:
<SeekBar
android:layout_width="match_parent"
android:layout_height="40dp"
android:progressDrawable="@drawable/seekbar_style"
/>
但它不起作用......我得到这个:
所以现在我尝试以编程方式进行,因为它可能是左,上,右,下DP的问题....这是代码,但结果不是我期待的......
int width = seekBar.getMeasuredWidth();
ShapeDrawable line = new ShapeDrawable();
line.getPaint().setStrokeWidth(3);
line.getPaint().setColor(Color.BLACK);
ShapeDrawable bubble1 = new ShapeDrawable(new OvalShape());
bubble1.setBounds(width, 1, 0, 1);
bubble1.getPaint().setColor(Color.WHITE);
bubble1.setIntrinsicHeight(25);
bubble1.setIntrinsicWidth(25);
//bubble2, bubble3, bubble4 with different colors and then:
Drawable[] layers = {line, bubble1, bubble2, bubble3, bubble4};
seekBar.setProgressDrawable(new LayerDrawable(layers));
有人能指出我正确的方向吗?我做错了什么?
答案 0 :(得分:1)
我不认为单独使用图层列表会让你随处可见。如果您不想创建自己的自定义搜索栏,我会在名称中检查一些带有SeekBar的自定义库,例如:
答案 1 :(得分:0)