首页 > 解决方案 > 防止在 webview 中移动按钮

问题描述

我在 webview 上有一个按钮,我想问当我沿着 webview 向下滚动时如何防止移动该按钮?我使用相对布局
我这样做了,但我正在寻找更好的解决方案

   webView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
        @Override
        public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (scrollX == 0 && scrollY == 0 ){
                myBtn.setVisibility(View.VISIBLE);
            }else{
                myBtn.setVisibility(View.GONE);
           }

        }
    });   

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFD0">

    <WebView
        android:id="@+id/webView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    </WebView>

    <Button
    android:id="@+id/myBtn"
        android:backgroundTint="#172632"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:textAllCaps="false"
        android:text="Scanner"
        />

</RelativeLayout>

标签: androidwebview

解决方案


推荐阅读