ScrollView 嵌套WebView 的问题优化
一.布局样式
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/graywhite"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_pb"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone" >
<ProgressBar
android:layout_width="20dp"
android:layout_height="20dp" />
</LinearLayout> <RelativeLayout
android:id="@+id/jg_rl_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/position3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@color/black" >
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/everyday_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:actualImageScaleType="centerCrop" />
<LinearLayout
android:id="@+id/ll_knowledge_head_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/reading_detail"
android:gravity="center"
android:orientation="horizontal" > <TextView
android:id="@+id/everyday_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="@dimen/font_14" /> </LinearLayout>
<com.ldcang.customview.MyTxVideo
android:id="@+id/my_tx_video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</com.ldcang.customview.MyTxVideo>
<TextView
android:id="@+id/tv_middle_play"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/play_start"
android:layout_centerInParent="true"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout> <WebView
android:id="@+id/everyday_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"/> </LinearLayout>
<com.ldcang.utils.Listview
android:id="@+id/everyday_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/graywhite"
android:divider="@null">
</com.ldcang.utils.Listview>
<LinearLayout
android:id="@+id/ll_goods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/white">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center_vertical"
android:text="猜你喜欢"
android:textColor="@color/text333"
android:textSize="@dimen/font_14"/>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/graywhite"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"> <LinearLayout
android:id="@+id/ll_collect_image_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:orientation="horizontal" />
</HorizontalScrollView> </LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/position3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_alignParentBottom="true"
android:orientation="vertical"> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/line" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="43dp"
android:orientation="horizontal"> <LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"> <TextView
android:id="@+id/zm_tv_zan"
android:layout_width="19dp"
android:layout_height="19dp"
android:background="@drawable/liulan_list" /> <TextView
android:id="@+id/everyday_views"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0"
android:textColor="@color/text666"
android:textSize="@dimen/font_14" />
</LinearLayout> <View
android:layout_width="1px"
android:layout_height="match_parent"
android:background="@color/line" /> <LinearLayout
android:id="@+id/ll_collect"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"> <ImageView
android:id="@+id/iv_collect"
android:layout_width="19dp"
android:layout_height="19dp"
android:background="@drawable/guanzhu" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="收藏"
android:textColor="@color/text666"
android:textSize="@dimen/font_14" />
</LinearLayout> <View
android:layout_width="1px"
android:layout_height="match_parent"
android:background="@color/line" /> <LinearLayout
android:id="@+id/everyday_share"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"> <TextView
android:id="@+id/zm_tv_share"
android:layout_width="17dp"
android:layout_height="17dp"
android:background="@drawable/jg_share" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="分享"
android:textColor="@color/text666"
android:textSize="@dimen/font_14" />
</LinearLayout> <View
android:layout_width="1px"
android:layout_height="match_parent"
android:background="@color/line" /> <LinearLayout
android:id="@+id/everyday_pinglun"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"> <TextView
android:id="@+id/textView3"
android:layout_width="18dp"
android:layout_height="18dp"
android:background="@drawable/comment_icon" /> <TextView
android:id="@+id/everyday_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="评论"
android:textColor="@color/text666"
android:textSize="@dimen/font_14" />
</LinearLayout> </LinearLayout>
</LinearLayout> <TextView
android:id="@+id/everyday_back"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/attention_back" />
</RelativeLayout>
</LinearLayout> 这个我布局我手机没问题就没注意,以为没有问题,后面部分手机会有很大的空白区域,滑动控件冲突了。以后遇到两个滑动控件嵌套都会有问题,必须自定义一个滑动控件,我认为最好是自定义嵌套的内部滑动控件,感觉比较简单。 二。自定义WebView
public class MyWebView extends WebView {
public MyWebView(Context context) {
super(context);
}
public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
主要复写onMeasure()方法 重新计算一下高度即可,然后在修改完的时候发现会滚动到WebView的位置
继续修改贴上部分代码
public class EveryDayDetailActivity extends BaseActivity implements OnClickListener {
@Override
protected void initView() {
// TODO Auto-generated method stub
setContentView(R.layout.everyday_detail);
jg_rl_parent = (RelativeLayout) findViewById(R.id.jg_rl_parent);
ll_pb = (LinearLayout) findViewById(R.id.ll_pb);
back = (TextView) findViewById(R.id.everyday_back);//返回 listView = (Listview) findViewById(R.id.everyday_listview); /** 有视频则显示视频播放 */ webView = (WebView) findViewById(R.id.everyday_webview);
title = (TextView) findViewById(R.id.everyday_title);
imageView = (SimpleDraweeView) findViewById(R.id.everyday_background);
/**
* 改为自定义控件自动滚动到了WebView,添加焦点不让滚动到WebView
* */
imageView.setFocusable(true);
imageView.requestFocus();
imageView.setFocusableInTouchMode(true); ll_knowledge_head_bottom = (LinearLayout) findViewById(R.id.ll_knowledge_head_bottom);
mMyTxVideo = (MyTxVideo) findViewById(R.id.my_tx_video);//视频空间
tv_middle_play = (TextView) findViewById(R.id.tv_middle_play);//播放按钮控件
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);//加载转圈 popshare = getLayoutInflater().inflate(R.layout.popupwindow_share, null);//分享弹框布局 /** 商品和拍卖 */
ll_goods = (LinearLayout)findViewById(R.id.ll_goods);//商品和拍卖父控件
ll_collect_image_container = (LinearLayout)findViewById(R.id.ll_collect_image_container);//商品和拍卖控件 /** 底部 */
views = (TextView) findViewById(R.id.everyday_views);
share = (LinearLayout) findViewById(R.id.everyday_share);
pinglun = (LinearLayout) findViewById(R.id.everyday_pinglun);
everyday_comment = (TextView) findViewById(R.id.everyday_comment);
iv_collect = (ImageView) findViewById(R.id.iv_collect);
ll_collect = (LinearLayout) findViewById(R.id.ll_collect);
}
}
把焦点给上面的任何一个控件就可以了
/**
* 改为自定义控件自动滚动到了WebView,添加焦点不让滚动到WebView
* */
imageView.setFocusable(true);
imageView.requestFocus();
imageView.setFocusableInTouchMode(true);
ScrollView 嵌套WebView 的问题优化的更多相关文章
- Android scrollview嵌套webview滑动冲突的解决方案
在Android开发中有时我们需要在scrollview中嵌套webview这时你会发现这两者的滑动事件产生了冲突导致:webview很难被滑动,即使被滑动了一点也非常不顺畅.解决方案也比较简单只需要 ...
- ScrollView嵌套RecyclerView时滑动出现的卡顿
原文连接:http://zhanglu0574.blog.163.com/blog/static/113651073201641853532259/ 现象: 一个界面有多个RecyclerView ...
- 关于ScrollView嵌套ListView问题
Android开发之ScrollView中嵌套ListView的解决方案 原文:http://blog.csdn.net/minimicall/article/details/40983331 ...
- [Android Pro] ScrollView嵌套RecyclerView时滑动出现的卡顿
reference to : http://zhanglu0574.blog.163.com/blog/static/113651073201641853532259/ ScrollView嵌套Rec ...
- (转)ViewPager,ScrollView 嵌套ViewPager滑动冲突解决
ViewPager,ScrollView 嵌套ViewPager滑动冲突解决 本篇主要讲解一下几个问题 粗略地介绍一下View的事件分发机制 解决事件滑动冲突的思路及方法 ScrollView 里面嵌 ...
- 四种方案解决ScrollView嵌套ListView问题(转)
以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollVie ...
- Scrollview 嵌套 RecyclerView 及在Android 5.1版本滑动时 惯性消失问题
标签:scrollview android 滑动 嵌套 scrollview 嵌套recyclerview 时,recyclerview不显示,这就需要我们自己计算recyclerview ...
- RecyclerView和ScrollView嵌套使用
我们的recyclerView有多个layoutmanager,通过重写layoutmanager的方法就可以让recyclerView和ScrollView嵌套了.但是请注意,如果recyclerV ...
- 解决ScrollView嵌套ViewPager出现的滑动冲突问题
/** * 解决ScrollView嵌套ViewPager出现的滑动冲突问题 */ public class ScrollView1 extends ...
随机推荐
- zabbix3.2安装手册
Alexei Vladishev创建了Zabbix项目,当前处于活跃开发状态,Zabbix SIA提供支持. Zabbix是一个企业级的.开源的.分布式的监控套件 Zabbix可以监控网络和服务的监控 ...
- 配置httpd虚拟主机
轻松配置httpd的虚拟主机 httpd使用VirtualHost指令进行虚拟主机的定义.支持三种虚拟主机:基于ip,基于端口和基于名称.其中基于端口的虚拟主机在httpd的术语上(例如官方手册)也属 ...
- python 面对对象基础
目录 面向对象基础 面向对象编程(抽象) 类与对象 给对象定制独有的特征 对象的属性查找顺序 类与对象的绑定方法 类与数据类型 对象的高度整合 面向对象基础 面向对象编程(抽象) 回顾一下 面向过程编 ...
- 七周成为数据分析师06_MySQL
关于 MySQL 的知识,主要也是一些实操和练习. 因为个人之前已经专门练习过 MySQL 操作,这里就不做笔记,之后另写一篇博文记录 MySQL 知识. 同时附上本课程对应的文字教程: 如何七周成为 ...
- hihocoder1174 拓扑排序1
#1174 : 拓扑排序·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 由于今天上课的老师讲的特别无聊,小Hi和小Ho偷偷地聊了起来. 小Ho:小Hi,你这学期有选 ...
- kettle-批量同步表数据
一.实验目标 利用kettle实现从mysql数据库中的dbf库批量同步表到dbm库(全量同步) 二.实验环境 dbf 库中表f1.f2.f3 .f1中1条数据,f2中100条数据,f3中2条数据 ...
- kettle 增量同步
http://www.cnblogs.com/inuyasha1027/p/Kettle_update_timestamp.html https://ask.hellobi.com/blog/yugu ...
- HTTP和HTTPS以及两者的区别
HTTP:是互联网上的应用广泛的一种网络协议,是一个客户端和服务器端请求和应答的传输协议,它可以使浏览器更加高效,使网络传输减少. HTTPS:是以安全为目标的HTTP通道,简单讲是HTTP的安全版, ...
- python基础学习笔记——网络编程(协议篇)
一 互联网的本质 咱们先不说互联网是如何通信的(发送数据,文件等),先用一个经典的例子,给大家说明什么是互联网通信. 现在追溯到八九十年代,当时电话刚刚兴起,还没有手机的概念,只是有线电话,那么此时你 ...
- Zend Framework 2中如何使用Service Manager
end Framework 2 使用ServiceManager(简称SM)来实现控制反转(IoC).有很多资料介绍了service managers的背景,我推荐大家看看this blog post ...