首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

施用setProgressDrawable()动态替换ProgressDrawable图片不好用

2013-01-02 
使用setProgressDrawable()动态替换ProgressDrawable图片不好用想在java代码中动态的改变seekbar的Progres

使用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等等。

热点排行