How to hide part of a view?

Asked

Viewed 71 times

1

I have the Stickerbtn.java with the following code:

public class StickerBtn extends View {

    private Bitmap mControllerBitmap

    private void init() {

        mControllerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_refreshing);
        mControllerWidth = mControllerBitmap.getWidth();
        mControllerHeight = mControllerBitmap.getHeight();


    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (stickers.size() <= 0) {
            return;
        }

        for (int i = 0; i < stickers.size(); i++) {
            stickers.get(i).getmMatrix().mapPoints(stickers.get(i).getMapPointsDst(), stickers.get(i).getMapPointsSrc());
            canvas.drawBitmap(stickers.get(i).getBitmap(), stickers.get(i).getmMatrix(), null);
            if (stickers.get(i).isFocusable()) {

                canvas.drawBitmap(mControllerBitmap, stickers.get(i).getMapPointsDst()[4] - mControllerWidth / 2, stickers.get(i).getMapPointsDst()[5] - mControllerHeight / 2, null);

                canvas.drawBitmap(mDeleteBitmap, stickers.get(i).getMapPointsDst()[0] - mDeleteWidth / 2, stickers.get(i).getMapPointsDst()[1] - mDeleteHeight / 2, null);

            }
        }

    }

And I have the Mainactivity.java with the following:

imgSave = (ImageView) findViewById(R.id.imgSave);
imgSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
...
}

What I have to put in place three points for when the user presses the save image it hides or removes the R.drawable.ic_refreshing?

I’ve tried the following, but the mistake, because it’s in another class:

mControllerBitmap.setVisibility(View.GONE);

Can someone help me?

  • Tries mControllerBitmap.setVisibility(View.INVISIBLE);

  • Do you want to hide the image from the button but keeping the button? What do you mean by "save it"?

  • I want you to press "R.id.imgSave" to remove "R.drawable.ic_refreshing" from the screen. When I try setvisibility, it says the following: Cannot resolveSymbol 'mControllerBitmap'.

  • R.drawable.ic_refreshing is used inside Stickerbtn. Where/how do you use Stickerbtn? It’s harder to figure out what you want than eventually to solve the problem.

  • What code do I have to use on mainactivity to manipulate the icon that is in the project’s drawable folder and is used in another class.

  • Just this is not enough, there are several possibilities. Where/how do you use Stickerbtn? Just want to hide the R.drawable.ic_refreshing and keep the Stickerbtn view?

  • Stickerbtn is created to stand next to an image that changes in size when you press the R.drawable.ic_refreshing button. I just want to hide R.drawable.ic_refreshing when the person is saving that image.

  • Stickerbtn and R.drawable.ic_refreshing are not the same thing?

  • R.drawable.ic_refreshing is one of the buttons that make up Stickerbtn. When the person selects the image they want to edit Stickerbtn, it creates several buttons around the image with editing options. One of these buttons is R.drawable.ic_refreshing, which I want to make it disappear.

Show 4 more comments

1 answer

2


Add a field to the Stickerbtn class to control whether Bitmap is drawn or not in the method onDraw().

private boolean drawControllerBitmap; // inicialize com true caso pretenda 
                                      // que inicialmente seja desenhado.

Add a Setter and possibly a getter to that field:

public void setControllerBitmapVisible(boolean visible){
    drawControllerBitmap = visible;
    invalidate(); //Isto faz com que o método onDraw seja chamado
}

public boolean getControllerBitmapVisible(){
    return drawControllerBitmap;
}

In the method onDraw() only draw Bitmap if drawControllerBitmap is true.

In the "place of three points" use setControllerBitmapVisible(false), of the instantiated object of the Stickerbtn class, to remove (not draw) R.drawable.ic_refreshing.

  • 1

    It worked perfectly, I started drawControllerBitmap as true, then controlled the display with setControllerBitmapVisible(). And only draw Bitmap if drawControllerBitmap is true. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.