Java 如何根据用户输入在webview前面隐藏和显示视图

Java 如何根据用户输入在webview前面隐藏和显示视图,java,android,webview,Java,Android,Webview,我目前正在从事一个项目,在该项目中,我使用了打包在RelativeLayout中的webview,并在左下角放置了一个ImageButton: <RelativeLayout android:id="@+id/relativeLayout_maincontent" android:layout_width="fill_parent" android:layout_height="fill_parent" > <W

我目前正在从事一个项目,在该项目中,我使用了打包在RelativeLayout中的webview,并在左下角放置了一个ImageButton:

<RelativeLayout
        android:id="@+id/relativeLayout_maincontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        />

        <ImageButton
            android:id="@+id/imageButton_call"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="2dp"
            android:src="@android:drawable/ic_menu_call" />

</RelativeLayout>
这很有效。下一步是在用户输入时显示按钮,因此我尝试了以下方法:

relativeLayout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(callButton.getVisibility() == ImageButton.GONE) callButton.setVisibility(ImageButton.VISIBLE);
                startCallButtonHidingThread();
                            return false;
           }
 });
或者:

relativeLayout.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if(callButton.getVisibility() == ImageButton.GONE) callButton.setVisibility(ImageButton.VISIBLE);
                startCallButtonHidingThread();

            }
        });
和我在webview上试过的一样。大多数情况下,它只工作一次,然后根本没有反应

因此,如果你有任何想法或更好的解决方案,请让我知道。
我真的很感谢你的帮助

我认为是安卓限制。尝试使用处理程序:

private Handler handler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what){
            case 1:{
                if(callButton.getVisibility() == ImageButton.GONE) callButton.setVisibility(ImageButton.VISIBLE);
                startCallButtonHidingThread();
            }
        }
};
还有你的听众:

relativeLayout.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            handler.sendEmptyMessage(1);
            return false;
        }
});

谢谢你的快速回答,但没有用。当我将TouchListener设置为relativeLayout时,它根本不起作用,但当我将Listener设置为webview时,它第一次起作用-按钮隐藏、显示和隐藏。但是在那之后什么也没有发生。用户输入在哪里?
relativeLayout.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            handler.sendEmptyMessage(1);
            return false;
        }
});