在下面的代码中,我面临的问题是在 onTouchListener 方法中,if 和 else 部分每次都被执行。有人知道为什么会这样吗?并且我的项目的目标是在 web 视图中的任何位置发生触摸事件,停靠布局必须出现在另一个触摸上,它必须消失。有人可以帮忙吗?
提前致谢 ..
public class MathiasdockActivity extends Activity {
/** Called when the activity is first created. */
RelativeLayout upperdock,parent;
LinearLayout tocbottom,tocparent;
boolean flag=true;
WebView wv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
parent=(RelativeLayout) findViewById(R.id.rl1);
upperdock=(RelativeLayout) findViewById(R.id.upperdock);
tocparent=(LinearLayout) findViewById(R.id.tocparent);
tocbottom=(LinearLayout) findViewById(R.id.linearLayout3);
upperdock.setVisibility(RelativeLayout.INVISIBLE);
tocparent.setVisibility(LinearLayout.INVISIBLE);
tocbottom.setVisibility(LinearLayout.INVISIBLE);
wv = (WebView) findViewById(R.id.webView1);
wv.loadUrl("file:///android_asset/hotspot/07-03.html");
wv.getSettings().setJavaScriptEnabled(true);
wv.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(flag)
{
Toast toast1 = Toast.makeText(getBaseContext(), Boolean.toString(flag) + "if", 1000);
toast1.show();
upperdock.bringToFront();
tocparent.bringToFront();
tocbottom.bringToFront();
upperdock.setVisibility(RelativeLayout.VISIBLE);
tocparent.setVisibility(LinearLayout.VISIBLE);
tocbottom.setVisibility(LinearLayout.VISIBLE);
flag=false;
}
else
{
Toast toast2 = Toast.makeText(getBaseContext(), Boolean.toString(flag) + "else", 1000);
toast2.show();
wv.bringToFront();
upperdock.setVisibility(RelativeLayout.INVISIBLE);
tocparent.setVisibility(LinearLayout.INVISIBLE);
tocbottom.setVisibility(LinearLayout.INVISIBLE);
flag=true;
}
return flag;
}
});
}
}