how to clear view in android?

笑着哭i 提交于 2019-12-04 07:14:15

Jus use ...

mCanvas.drawColor(Color.BLACK);

... for clearing the canvas or any other color you want to have in background. E.g.

remove.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // clear canvas contents  
        mCanvas.drawColor(Color.BLACK);

        // create new path list; old one will be garbage collected 
        ConcurrentLinkedQueue<Map.Entry<Path, DrawingPens>> mPaths = 
                  new ConcurrentLinkedQueue<Map.Entry<Path, DrawingPens>>();

        pens.setVisibility(View.VISIBLE);
    }

p.s.: for removing a view dynamically from its container use removeView(....), e.g.

((ViewGroup)viewToRemove.getParent()).removeView(viewToRemove);

Hope this helps ... Cheers!

remove.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                layout.removeView(mDrawView);
                mDrawView = new SingleTouchView(MainActivity.this);
                layout.addView(mDrawView);
            }
        });
user2041902

Put the portion of the screen you want cleared in a single layout in xml eg

<RelativeLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height= "wrap_content">

    The Views that have to be gone on click

</RelativeLayout>

Then in your code in onClick() of the button give

((RelativeLayout) findViewById(R.id.layout)).setVisiblity(View.GONE));

EDIT :

If you want the ImageView cleared use :

((ImageView) findViewById(R.id.imageView)).setImageDrawable(null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!