Android中ViewPager如何使用WebView

发布时间:2021-08-09 10:40:33 作者:小新
来源:亿速云 阅读:137

小编给大家分享一下Android中ViewPager如何使用WebView,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

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

前言:

今天在做项目时遇到了一个小问题

首先使用ViewPager显示多个页面,然后在每个页面上使用Fragment显示数据,其中有一部分数据是通过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>

问题是当数据加载完毕之后,WebView会自动移动到页面的最顶端,如果用户想查看处于WebView上方的TextView内容则必须手动将页面往下拉

解决以上问题可以在Scrollview中所使用的LinearLayout添加如下属性:

android:descendantFocusability="blocksDescendants"

以上是“Android中ViewPager如何使用WebView”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. Android WebView详解
  2. android Viewpager onscrolled事件使用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android viewpager webview

上一篇:mac系统中AndroidStudio怎么用

下一篇:如何使用IntelliJ IDEA配置Maven

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》