use the following code, but can not be replaced by new images only, and the original image are gone, the display is blank.
please adequate guidance, thanks
mSeekBar.setProgressDrawable (this.getResources (). getDrawable (R.drawable.ProgressDrawable));
added:
However, if you use the following code to draw
mSeekBar.setProgressDrawable (this.getResources (). getDrawable (aa.getDrawingCache ()))
aa the screen not a view.
------ Solution -------------------------- ------------------
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
mApplyGravity = true;
}
This function is protected, it can not be called directly, but look at the source code found in Drawable's setBounds will call this function. As follows:
/**
* 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);
}
can call setBounds ().
setGravity and view setgravity is the same value passed in is Gravity of static variables. If Gravity.LEFT so on.
------ reference --------------------------------------- < br> After my several tests, and finally found the problem lies.
In BitmapDrawable the draw (canvas) in
@Override
public void draw(Canvas canvas) {
Bitmap bitmap = mBitmap;
if (bitmap != null) {
final BitmapState state = mBitmapState;
if (mRebuildShader) {
Shader.TileMode tmx = state.mTileModeX;
Shader.TileMode tmy = state.mTileModeY;
if (tmx == null && tmy == null) {
state.mPaint.setShader(null);
} else {
Shader s = new BitmapShader(bitmap,
tmx == null ? Shader.TileMode.CLAMP : tmx,
tmy == null ? Shader.TileMode.CLAMP : tmy);
state.mPaint.setShader(s);
}
mRebuildShader = false;
copyBounds(mDstRect);
}
Shader shader = state.mPaint.getShader();
if (shader == null) {
if (mApplyGravity) {
Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight,
getBounds(), mDstRect);
mApplyGravity = false;
}
canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint);
} else {
if (mApplyGravity) {
mDstRect.set(getBounds());
mApplyGravity = false;
}
canvas.drawRect(mDstRect, state.mPaint);
}
}
}
red part of the word, because mApplyGravity is false (the default value), it will not enter the branch, causing mDstRect as ((0,0) - (0,0)), so in canvas.drawBitmap (bitmap , null, mDstRect, state.mPaint) will not draw.
------ reference --------------------------------------- < br> mApplyGravity this value in the following code is set to true.
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
mApplyGravity = true;
}
/** Set the gravity used to position/stretch the bitmap within its bounds.
See android.view.Gravity
* @param gravity the gravity
*/
public void setGravity(int gravity) {
mBitmapState.mGravity = gravity;
mApplyGravity = true;
}
so you can setProgressDrawable () before you set about gravity, so that you can draw it.
------ reference ------------------------------------ ---
sorry, did not understand this too, can not be said that the detailed points in it
This method is inherited who follows the way. Yeah I was directly coupled to be wrong, there mApplyGravity who pass this change have set up.
@ Override
protected void onBoundsChange (Rect bounds) {
super.onBoundsChange (bounds);
mApplyGravity = true;
}
mBitmapState this is what type, gravity that want to pass anything.
public void setGravity (int gravity) {
mBitmapState.mGravity = gravity;
mApplyGravity = true;
}
------ reference --------------------------- ------------
very grateful to Kazakhstan, easy to use method
collate the results so that other people use.
Drawable progressDrawable = his.getResources (). getDrawable (R.drawable.ProgressDrawable);
progressDrawable.setBounds (0, 5, 806, 30);
seekBar.setProgressDrawable (progressDrawable);
------ reference ----------------------------- ----------
Thank you very much, just use
------ reference --------------------- ------------------
a great help thanks ah
google for a long time, are copied to change xml code
------ reference ------------------------ ---------------
but there are problems ah ...
if (oldBounds.left! = left | | oldBounds.top! = top | |
oldBounds.right! = right | | oldBounds.bottom! = bottom) {
mBounds.set (left, top, right, bottom);
onBoundsChange (mBounds);
}
If I do not want to change the values of these bounds, how to do it
------ reference ----------------------- ----------------
I have encountered this problem, I would like to know progressDrawable.setBounds (0, 5, 806, 30);
parameters to pass to the inside how to fill
------ reference ---------------------------- -----------
progressDrawable = this.getResources (). getDrawable (R.drawable.image);
progressDrawable.setBounds (mSeekBar.getProgressDrawable (). getBounds ());
mSeekBar.setProgressDrawable (progressDrawable);
Try this
------ reference ------------------------------- --------
good landlord, then scattered dotted bar
------ reference --------------------- ------------------
progressDrawable = this.getResources (). getDrawable (R.drawable.image);
progressDrawable.setBounds (mSeekBar.getProgressDrawable (). getBounds ());
mSeekBar.setProgressDrawable (progressDrawable);
this is indeed the normal load, but becomes a drag strip have become a whole load of pictures (slide did not even get to the part are displayed)
How can we solve?
------ reference --------------------------------------- < br> progressDrawable = this.getResources (). getDrawable (R.drawable.image);
progressDrawable.setBounds (mSeekBar.getProgressDrawable (). getBounds ());
mSeekBar.setProgressDrawable (progressDrawable);
mSeekBar.setProgress (0);
progressbar is not changed if progress is not refresh the image, so choose the schedule is set to 0 to try.
------ reference --------- ------------------------------
code inside setProgressDrawable () This method is called after the layout is shown in only one picture, which is why? Before I call this layout in the xml inside two background images can be displayed after it is in drag is another one picture, but why two of the code inside the preliminary effect it? This picture when I call the code inside the effect of this layout, I want to have the effect of dragging the effect is the following goes before a gray background picture
------ reference --- ------------------------------------
I have encountered this problem. I want to achieve power display, I use a progressbar. I registered a radio, battery change when the change progressbar color, but now the color can not get out ah. Use the following code does not work.
progressDrawable = this.getResources (). getDrawable (R.drawable.image);
progressDrawable.setBounds (mSeekBar.getProgressDrawable (). getBounds ());
mSeekBar.setProgressDrawable (progressDrawable);
is how it happened?
------ reference --------------------------------------- < br> You all're wrong, change colors not setProgressDrawable, but setBackgroundResource (int resid), Progress with ImageView not the same.
没有评论:
发表评论