Android WebView 文明踩坑之路

來源:互聯網
上載者:User

標籤: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 文明踩坑之路

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.