我设法在android中以编程方式创建了seekbar,但被困在使矩形拇指居中并正确调整它的高度。如何让拇指居中?
编辑:附加代码注意:代码在javascript中,但它相当于在java中可以完成的事情(我正在使用可以完成的环境)
function setSeekBarProgress(){
var shape=new android.graphics.drawable.GradientDrawable();
shape.setOrientation(android.graphics.drawable.GradientDrawable.Orientation.BOTTOM_TOP);
shape.setColor(android.graphics.Color.BLUE);
shape.setCornerRadius(50);
shape.setSize(600,200);
shape.setBounds(0,0,600,200);
var clip=new android.graphics.drawable.ClipDrawable(shape,android.view.Gravity.LEFT,android.graphics.drawable.ClipDrawable.HORIZONTAL);
shape=new android.graphics.drawable.GradientDrawable();
shape.setOrientation(android.graphics.drawable.GradientDrawable.Orientation.BOTTOM_TOP);
shape.setColor(android.graphics.Color.BLACK);
shape.setCornerRadius(50);
shape.setSize(1000,200);
shape.setBounds(0,0,1000,200);
var insetDrawable=new android.graphics.drawable.InsetDrawable(shape,5,5,5,5);
var a=[];
var drawableArray= java.lang.reflect.Array.newInstance(android.graphics.drawable.Drawable.class,2);
drawableArray[0]=insetDrawable;
drawableArray[1]=clip;
var myLayer = new android.graphics.drawable.LayerDrawable(drawableArray);
nativeSeekBar.setProgressDrawable(myLayer);
}
以及创建 seekbar 的代码:
nativeSeekBar=new android.widget.SeekBar(args.context,null, android.R.attr.progressBarStyleHorizontal);
setSeekBarProgress();
var RoundRecFirstArg= java.lang.reflect.Array.newInstance(java.lang.Float.class.getField("TYPE").get(null),8);
RoundRecFirstArg[0]=2;
RoundRecFirstArg[1]=2;
RoundRecFirstArg[2]=2;
RoundRecFirstArg[3]=2;
RoundRecFirstArg[4]=2;
RoundRecFirstArg[5]=2;
RoundRecFirstArg[6]=2;
RoundRecFirstArg[7]=2;
var thumb=new android.graphics.drawable.ShapeDrawable(new android.graphics.drawable.shapes.RoundRectShape(RoundRecFirstArg,null,null));
thumb.getPaint().setColor(android.graphics.Color.rgb(133,133,133));
thumb.setIntrinsicHeight(200);
thumb.setIntrinsicWidth(80);
nativeSeekBar.setThumb(thumb);
nativeSeekBar.setProgress(20);