Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 隐藏按钮并在触摸时再次显示_Android_Touch_Hide_Visible_Invisible - Fatal编程技术网

Android 隐藏按钮并在触摸时再次显示

Android 隐藏按钮并在触摸时再次显示,android,touch,hide,visible,invisible,Android,Touch,Hide,Visible,Invisible,我正在开发一个应用程序,在这个应用程序中,我想隐藏按钮,或者说,当我触摸屏幕时,使按钮不可见,当我再次触摸屏幕时,使按钮可见 如何实现它?实现一个onTouchListener // Catch touch events here @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { System.out

我正在开发一个应用程序,在这个应用程序中,我想隐藏按钮,或者说,当我触摸屏幕时,使按钮不可见,当我再次触摸屏幕时,使按钮可见


如何实现它?

实现一个onTouchListener

 // Catch touch events here
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        System.out.println("Touch Down X:" + event.getX() + " Y:" + event.getY());
    } 
    if (event.getAction() == MotionEvent.ACTION_UP) {
        System.out.println("Touch Up X:" + event.getX() + " Y:" + event.getY());
    }
    return super.onTouchEvent(event);
}
然后,在此对话框中,您将要引用按钮并设置其可见性:

  button1.setVisibility(View.VISIBLE); or View.INVISIBLE

试试这个。这可能会解决你的问题

    LinearLayout mainLay = (LinearLayout) findViewById(R.id.lLay);
    int flagForButton = 0;
    Button b1 = new Button(this);
    b1.setVisibility(0);

    mainLay .setOnTouchListener(new OnTouch Listener)
    {
        public boolean onTouchEvent(MotionEvent event)
        {
            int action = event.getAction();
            if (action==0)
            {
            }
            else
                if (action == 1)
                {
                    if (flagForButton ==1)
                    {
                        b1.setVisibility(0);
                        flagForButton = 0;
                    }
                    else
                    {
                        b1.setVisibility(4);
                        flagForButton = 1;
                    }
                }
        }
    });

View.GONE
也可能有用。