所以我能够自己回答这个问题......我使用路径来创建可绘制对象,然后将它们缝合在一起以创建平行四边形。
public Drawable createThumbDrawable(boolean checked){
Path path = new Path();
path.moveTo(0, 0);
path.lineTo(1, 0);
path.lineTo(1, 1);
path.lineTo(0, 1);
path.close();
PathShape shape = new PathShape(path, 1, 1);
ShapeDrawable drawable = new ShapeDrawable(shape);
if (checked){
drawable.getPaint().setColor(Color.CYAN);
}
else
{
drawable.getPaint().setColor(Color.BLACK);
}
mThumbLeftDrawable = createLeftThumbDrawable(checked);
mThumbRightDrawable = createRightThumbDrawable(checked);
return drawable;
}
public Drawable createLeftThumbDrawable(boolean checked){
Path path = new Path();
path.moveTo(0, 25);
path.lineTo(25, 0);
path.lineTo(25, 25);
path.close();
PathShape shape = new PathShape(path, 25, 25);
ShapeDrawable drawable = new ShapeDrawable(shape);
if (checked){
drawable.getPaint().setColor(Color.CYAN);
}
else
{
drawable.getPaint().setColor(Color.BLACK);
}
return drawable;
}
public Drawable createRightThumbDrawable(boolean checked){
Path path = new Path();
path.moveTo(0,0);
path.lineTo(25, 0);
path.lineTo(0, 25);
path.close();
PathShape shape = new PathShape(path, 25, 25);
ShapeDrawable drawable = new ShapeDrawable(shape);
if (checked){
drawable.getPaint().setColor(Color.CYAN);
}
else
{
drawable.getPaint().setColor(Color.BLACK);
}
return drawable;
}
public void setChecked(boolean checked) {
//Log.d(TAG, "setChecked("+checked+")");
boolean lc = checked;
if (!mTextOnThumb) {
lc = !checked;
}
if (checked){
mThumbDrawable = createThumbDrawable(checked);//this.getContext().getResources().getDrawable(R.drawable.slide_off);
}
else {
mThumbDrawable = createThumbDrawable(checked);//this.getContext().getResources().getDrawable(R.drawable.slide);
}
super.setChecked(checked);
mThumbPosition = lc ? getThumbScrollRange() : 0;
invalidate();
}