Android开发。 webview不会在touchevent上消失

问题描述 投票:0回答:1

这是我的代码

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

它什么也没做我希望触摸屏幕时Web视图消失。该网络视图用于托管广告。

我的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>
android webview touch
1个回答
0
投票

过去,我在使用FrameLayout时出现可见性问题,所以我建议您切换到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以外的所有屏幕。

© www.soinside.com 2019 - 2024. All rights reserved.