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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

Danny_姜   2021-03-29 我要评论
想了解Android 中ViewPager中使用WebView的注意事项的相关内容吗,Danny_姜在本文为您仔细讲解ViewPager WebView的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,中ViewPager中使用WebView,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"

如有疑问请留言或到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们