溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android中ViewPager如何使用WebView

發(fā)布時間:2021-08-09 10:40:33 來源:億速云 閱讀:150 作者:小新 欄目:移動開發(fā)

小編給大家分享一下Android中ViewPager如何使用WebView,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

Android 中ViewPager中使用WebView的注意事項

前言:

今天在做項目時遇到了一個小問題

首先使用ViewPager顯示多個頁面,然后在每個頁面上使用Fragment顯示數(shù)據(jù),其中有一部分數(shù)據(jù)是通過WebView加載的Html標簽。

具體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>

問題是當數(shù)據(jù)加載完畢之后,WebView會自動移動到頁面的最頂端,如果用戶想查看處于WebView上方的TextView內(nèi)容則必須手動將頁面往下拉

解決以上問題可以在Scrollview中所使用的LinearLayout添加如下屬性:

android:descendantFocusability="blocksDescendants"

以上是“Android中ViewPager如何使用WebView”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI