目前我正在尝试创建自定义Seekbar而不使用xml,因为背景和进度条的图像需要更改。这就是我现在所拥有的:
Drawable drawable = new BitmapDrawable(appState.images.get(Integer.parseInt(image)));
this.setBackgroundDrawable(drawable);
Drawable drawable2 = new BitmapDrawable(appState.images.get(Integer.parseInt(image_a)));
this.setProgressDrawable(drawable2);
this.setProgress(0);
但是progressDrawable只是设置为Seekbar的整个大小,当我将拇指从一侧移到另一侧时没有任何反应。有没有人有任何想法,因为我完全被难倒。
答案 0 :(得分:4)
所以这个以前的答案为你做了诀窍:
Changing the size of the seekbar programmatically but cant get the thumb to be larger than the bar
来自原始提问者:
最后我使用的是这段代码:
public void setSeekBarImages(){
Drawable drawable = new
BitmapDrawable(appState.images.get(Integer.parseInt(image_a)));
ClipDrawable clip = new ClipDrawable(drawable,
Gravity.LEFT,ClipDrawable.HORIZONTAL);
Drawable drawable2 = new
BitmapDrawable(appState.images.get(Integer.parseInt(image)));
InsetDrawable d1= new InsetDrawable(drawable2,5,5,5,5);
//the padding u want to use
setThumb(null);
LayerDrawable mylayer = new LayerDrawable(new Drawable[]{d1,clip});
setProgressDrawable(mylayer);
setProgress(0);
}