標籤:match htm red before www android edittext 圖片 html
情景一
webview 以頭布局的形式添加到 RecyclerView 中,第一次進入頁面,當頁面中有 EditText 並且點擊時,甚至是類似點贊更換圖片、點擊 WebView 任意地區,都會造成 WebView 自動滑動到最頂部;
分析:我的 WebView 在 onPageFinish() 的時候進行重新測量了高度,所以點擊事件等很可能是 WebView 擷取焦點重新繪製了,故而想到不讓WebView擷取焦點,嘗試過使用
android:focusable="true" android:focusableInTouchMode="true
上述代碼只能解決 WebView 地區以外的點擊造成的WebView滑動至頂部問題,第一次進入 WebView 時點擊依然會造成 WebView 滾動;最後想到了 code android:descendantFocusability="blocksDescendants",貌似完美解決
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:descendantFocusability="blocksDescendants"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout>
descendantFocusability 屬性說明:
beforeDescendants:viewgroup會優先其子類控制項而擷取到焦點 afterDescendants:viewgroup只有當其子類控制項不需要擷取焦點時才擷取焦點 blocksDescendants:viewgroup會覆蓋子類控制項而直接獲得焦點
情景二
Android 5.0 + 部分手機上 WebView 載入 GIF圖時 會造成 WebView 不停的閃爍
解決方案查看我的另一篇文章:WebView 5.0+閃爍以及白屏問題完美解決
Android WebView 文明踩坑之路