Android 中ViewPager中使用WebView的注意事項
Android 中ViewPager中使用WebView的注意事項
前言:
今天在做項目時遇到了一個小問題
首先使用ViewPager顯示多個頁面,然后在每個頁面上使用Fragment顯示數(shù)據(jù),其中有一部分?jǐn)?shù)據(jù)是通過WebView加載的Html標(biāo)簽。
具體xml布局如下
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/background" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/article_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:layout_marginBottom="2dp" android:text="Some Title" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/article_title" android:textStyle="bold" /> <LinearLayout android:id="@+id/LL_Seperator" android:layout_width="fill_parent" android:layout_height="1dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:background="@color/text" android:orientation="horizontal" > </LinearLayout> <WebView android:id="@+id/article_content" android:layout_width="match_parent" android:layout_marginRight="10dp" android:layout_marginLeft="10dp" android:layout_height="wrap_content" /> <TextView android:id="@+id/article_link" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginTop="5dp" android:layout_marginRight="10dp" android:layout_marginLeft="10dp" android:text="View Full Article" android:textColor="@color/article_title" android:textStyle="bold" /> </LinearLayout> </ScrollView>
問題是當(dāng)數(shù)據(jù)加載完畢之后,WebView會自動移動到頁面的最頂端,如果用戶想查看處于WebView上方的TextView內(nèi)容則必須手動將頁面往下拉
解決以上問題可以在Scrollview中所使用的LinearLayout添加如下屬性:
android:descendantFocusability="blocksDescendants"
如有疑問請留言或到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
- Android Studio 導(dǎo)入開源項目的正確姿勢及注意事項
- Android Studio3.0升級后使用注意事項及解決方法
- Android 程序執(zhí)行Linux命令的解決方法及注意事項
- 將Eclipse工程轉(zhuǎn)Android Studio工程的步驟與注意事項
- AndroidStudio升級到3.0的新特性和注意事項小結(jié)
- 詳解Android Service 使用時的注意事項
- Android TimerTask 的簡單應(yīng)用及注意事項
- Android 如何使用log4j及注意事項
- Android集成百度地圖開發(fā)流程和注意事項
- Android onNewIntent()觸發(fā)機(jī)制及注意事項
- Android Studio添加第三方庫的注意事項
- Android 程序申請權(quán)限注意事項
- Android Service自啟動注意事項分析
- 關(guān)于Android WebView的loadData方法的注意事項分析
- Android NDK中socket的用法以及注意事項分析
- Android生存指南之:開發(fā)中的注意事項
- Android 編程下字庫的使用及注意事項
- 60條Android開發(fā)注意事項與經(jīng)驗總結(jié)
相關(guān)文章
BroadcastReceiver靜態(tài)注冊案例詳解
這篇文章主要為大家詳細(xì)介紹了BroadcastReceiver靜態(tài)注冊案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-08-08Android RecyclerView實現(xiàn)點擊條目刪除
這篇文章主要為大家詳細(xì)介紹了Android RecyclerView實現(xiàn)點擊條目刪除,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-11-11