繁体   English   中英

安卓开发。 webview不会消失ontouchevent

[英]Android Development. webview doesn't disappear ontouchevent

这是我的代码

  public boolean onTouchEvent(MotionEvent event) {
    wv.setVisibility(View.GONE);
    return true; // Required for receiving subsequent events (ACTION_MOVE, ACTION_UP)
}

它没有做任何我希望触摸屏幕时 webview 消失的事情。 网络视图用于托管广告。

我的activity_main.xml 代码是:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.catching.apples.MainActivity"
tools:ignore="MergeRootFrame">


<WebView
android:id="@+id/activity_main_webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     />
<WebView
    android:id="@+id/webbanner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|bottom" />

</FrameLayout>

过去,我在使用FrameLayout遇到 Visibility 问题,所以我建议您切换到LinearLayout来解决这个问题。

将您的布​​局更改为:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.catching.apples.MainActivity"
    tools:ignore="MergeRootFrame">

    <WebView
        android:id="@+id/activity_main_webview"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1" />

    <WebView
        android:id="@+id/webbanner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />
</LinearLayout>

使用wv.setVisibility(View.GONE); ,现在我要工作了。

并使用layout_height="0dip" and layout_weight="1"activity_main_webview将适合除webbanner之外的所有屏幕。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM