使用setProgressDrawable()动态替换ProgressDrawable图片不好用
想在java代码中动态的改变seekbar的ProgressDrawable图片
使用了如下代码,但是不但不能换成新的图片,而且原来的图片也不见了,显示为空白。
请高人指点,感谢
mSeekBar.setProgressDrawable(this.getResources().getDrawable(R.drawable.ProgressDrawable));
补充:
不过如果使用如下代码就可以描画
mSeekBar.setProgressDrawable(this.getResources().getDrawable(aa.getDrawingCache()))
aa为本画面中的别一个view.
[解决办法]
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
mApplyGravity = true;
}
这个函数是protected,所以不能直接调用,但是看源代码发现在Drawable的setBounds中会调用这个函数。如下:
/**
* Specify a bounding rectangle for the Drawable. This is where the drawable
* will draw when its draw() method is called.
*/
public void setBounds(int left, int top, int right, int bottom) {
Rect oldBounds = mBounds;
if (oldBounds == ZERO_BOUNDS_RECT) {
oldBounds = mBounds = new Rect();
}
if (oldBounds.left != left
[解决办法]
oldBounds.top != top
[解决办法]
oldBounds.right != right
[解决办法]
oldBounds.bottom != bottom) {
mBounds.set(left, top, right, bottom);
onBoundsChange(mBounds);
}
}
/**
* Specify a bounding rectangle for the Drawable. This is where the drawable
* will draw when its draw() method is called.
*/
public void setBounds(Rect bounds) {
setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
}
可以调用setBounds()。
setGravity和view的setgravity是相同的,传入的值为Gravity的静态变量。如Gravity.LEFT等等。