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

 更新时间:2017年09月06日 11:44:48   作者:Danny_姜  
这篇文章主要介绍了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"

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

相关文章

  • Kotlin server多线程编程详细讲解

    Kotlin server多线程编程详细讲解

    这篇文章主要介绍了Kotlin server多线程编程,Service是实现程序后台运行的解决方案,适合执行非交互,后台预先的任务,即使用户打开其他应用,Service也能够正常运行
    2023-01-01
  • Android自定义验证码输入框的方法实例

    Android自定义验证码输入框的方法实例

    这篇文章主要给大家介绍了关于Android自定义验证码输入框的相关资料,文中通过实例代码介绍的非常详细,对各位Android开发者们具有一定的参考学习价值,需要的朋友可以参考下
    2022-02-02
  • 浅谈Android插件化

    浅谈Android插件化

    插件化技术最初源于免安装运行 Apk的想法,这个免安装的 Apk 就可以理解为插件,而支持插件的 app 我们一般叫 宿主,下面就跟着小编一起学习Android插件化吧,希望能帮助到你
    2021-09-09
  • Android实现截图分享qq 微信功能

    Android实现截图分享qq 微信功能

    在日常生活中,经常用到qq,微信截图分享功能,今天小编通过本文给大家介绍Android实现截图分享qq 微信功能,具体实现代码大家参考下本文
    2017-12-12
  • BroadcastReceiver静态注册案例详解

    BroadcastReceiver静态注册案例详解

    这篇文章主要为大家详细介绍了BroadcastReceiver静态注册案例,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-08-08
  • Android多种支付方式的实现示例

    Android多种支付方式的实现示例

    App的支付流程,添加多种支付方式,不同的支付方式,对应的操作不一样,有的会跳转到一个新的webview,有的会调用系统浏览器,有的会进去一个新的表单页面,等等,本文就给大家详细介绍一下Android 多种支付方式的优雅实现,需要的朋友可以参考下
    2023-09-09
  • Android开发之资源文件用法实例总结

    Android开发之资源文件用法实例总结

    这篇文章主要介绍了Android开发之资源文件用法,结合实例形式总结分析了Android开发过程中针对资源文件的常见操作技巧,需要的朋友可以参考下
    2016-02-02
  • 安卓输入框被虚拟键盘挡住的问题(微信开发)

    安卓输入框被虚拟键盘挡住的问题(微信开发)

    这篇文章主要介绍了安卓输入框被虚拟键盘挡住的问题(微信开发)的相关资料,需要的朋友可以参考下
    2016-04-04
  • Android RecyclerView实现点击条目删除

    Android RecyclerView实现点击条目删除

    这篇文章主要为大家详细介绍了Android RecyclerView实现点击条目删除,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-11-11
  • Android实现局部模糊效果

    Android实现局部模糊效果

    这篇文章主要为大家详细介绍了Android实现局部模糊效果,帮助大家实现模糊或者毛玻璃效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-07-07

最新评论