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 Studio 导入开源项目的正确姿势及注意事项
- Android Studio3.0升级后使用注意事项及解决方法
- Android 程序执行Linux命令的解决方法及注意事项
- 将Eclipse工程转Android Studio工程的步骤与注意事项
- AndroidStudio升级到3.0的新特性和注意事项小结
- 详解Android Service 使用时的注意事项
- Android TimerTask 的简单应用及注意事项
- Android 如何使用log4j及注意事项
- Android集成百度地图开发流程和注意事项
- Android onNewIntent()触发机制及注意事项
- Android Studio添加第三方库的注意事项
- Android 程序申请权限注意事项
- Android Service自启动注意事项分析
- 关于Android WebView的loadData方法的注意事项分析
- Android NDK中socket的用法以及注意事项分析
- Android生存指南之:开发中的注意事项
- Android 编程下字库的使用及注意事项
- 60条Android开发注意事项与经验总结
相关文章
详谈自定义View之GridView单选 金额选择Layout-ChooseMoneyLayout
下面小编就为大家带来一篇详谈自定义View之GridView单选 金额选择Layout-ChooseMoneyLayout。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-05-05
基于Android studio3.6的JNI教程之ncnn之语义分割ENet
这篇文章主要介绍了基于Android studio3.6的JNI教程之ncnn之语义分割ENet的相关知识,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值 ,需要的朋友可以参考下2020-03-03
android的RecyclerView实现拖拽排序和侧滑删除示例
在平时开发应用的时候,经常会遇到列表排序、滑动删除的需求。这篇文章主要介绍了android的RecyclerView实现拖拽排序和侧滑删除示例,有兴趣的可以了解一下。2017-02-02


最新评论