horizontalscrollview如何同步两个HorizontalScrollView滚动效果

horizontalscrollview  时间:2021-06-20  阅读:()

HorizontalScrollView初始如何滚动到某一值?

经过我的实验,一下代码可以完美解决问题。

: new Handler().postDelayed((new Runnable() { @Override public void run() { sv_price.scrollTo(((RadioButton)rg_price.getChildAt(housePriceIndex)).getLeft()-100,0); } }),5);其中 ((RadioButton)rg_price.getChildAt(housePriceIndex)).getLeft()-100是我想把HorizontalScrollView sv_price滚动到的最终位置。

最后的一个5是延迟的时间。

正如9楼所说,我刚开始用的 handler.post 果断无效!这个好用!!

如果ListView中嵌套HorizontalScrollView怎么解决滑动错乱

最近在开发中遇到HorizontalScrollView嵌套ScrollView导致滑动卡的情况,急横向水平滑动的View和垂直水平滑动的View,都在接收处理滑动时间,但是这种情况下触摸事件就会发生冲突。

导致滑动非常卡,甚至出现程序停止响应。

这种情况下我们需要重写view。

下面是两个简单的例子,重写水平滑动View只接收水平方向上滑动的事件。

我们使用手势GestureDetector来作区分。

<em>import android.content.Context; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; import android.view.View; import android.widget.HorizontalScrollView; public class CustomHScrollView extends HorizontalScrollView{ private GestureDetector mGestureDetector; private View.OnTouchListener mGestureListener; private static final String TAG = "CustomHScrollView"; /** * @function CustomHScrollView constructor * @param context Interface to global information about an application environment. * */ public CustomHScrollView(Context context) { super(context); // TODO Auto-generated constructor stub mGestureDetector = new GestureDetector(new HScrollDetector()); setFadingEdgeLength(0); } /** * @function CustomHScrollView constructor * @param context Interface to global information about an application environment. * @param attrs A collection of attributes, as found associated with a tag in an XML document. */ public CustomHScrollView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub mGestureDetector = new GestureDetector(new HScrollDetector()); setFadingEdgeLength(0); } /** * @function CustomHScrollView constructor * @param context Interface to global information about an application environment. * @param attrs A collection of attributes, as found associated with a tag in an XML document. * @param defStyle style of view */ public CustomHScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub mGestureDetector = new GestureDetector(new HScrollDetector()); setFadingEdgeLength(0); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev); } // Return false if we're scrolling in the y direction class HScrollDetector extends SimpleOnGestureListener { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if(Math.abs(distanceX) > Math.abs(distanceY)) { return true; } return false; } } } </em>

如何同步两个HorizontalScrollView滚动效果

可以尝试使用 GestureDetector, 我仅仅是理论上的描述,暂时没有环境可以运行。

假设是 scrollView1 带动 scrollView2。

在 scrollView1.setOnTouchListener() 里的事件传给 detector: detector.onTouchEvent( event ); 之后在 detectorListener 里: public boolean onScroll( MotionEvent e1, MotionEvent e2, float distanceX, float distanceY ) { int disX = ( int ) distanceX; scrollView2.scrollBy( disX, 0 ); return true; } 没有验证过,但我觉得八九不离十。

GeorgeDatacenter:洛杉矶/达拉斯/芝加哥/纽约vps云服务器;2核/8GB/250GB/2TB流量/1Gbps端口,$84/年

georgedatacenter怎么样?GeorgeDatacenter是一家2017年成立的美国商家,正规注册公司(REG: 10327625611),其实是oneman。现在有优惠,有几款特价VPS,基于Vmware。支持Paypal付款。GeorgeDatacenter目前推出的一款美国vps,2核/8GB内存/250GB NVMe空间/2TB流量/1Gbps端口/Vmware/洛杉矶/达拉...

新加坡云服务器 1核2Gg 46元/月 香港云服务器 1核2G 74元/月 LightNode

LightNode是一家成立于2002年,总部位于香港的VPS服务商。提供基于KVM虚拟化技术.支持CentOS、Ubuntu或者Windows等操作系统。公司名:厦门靠谱云股份有限公司官方网站:https://www.lightnode.com拥有高质量香港CN2 GIA与东南亚节点(河内、曼谷、迪拜等)。最低月付7.71美金,按时付费,可随时取消。灵活满足开发建站、游戏应用、外贸电商等需求。首...

ZJI:韩国BGP+CN2线路服务器,国内三网访问速度优秀,8折优惠码每月实付440元起

zji怎么样?zji最近新上韩国BGP+CN2线路服务器,国内三网访问速度优秀,适用8折优惠码zji,优惠后韩国服务器最低每月440元起。zji主机支持安装Linux或者Windows操作系统,会员中心集成电源管理功能,8折优惠码为终身折扣,续费同价,全场适用。ZJI是原Wordpress圈知名主机商:维翔主机,成立于2011年,2018年9月启用新域名ZJI,提供中国香港、台湾、日本、美国独立服...

horizontalscrollview为你推荐
财务系统软件常用财务软件有哪些?爱短信官网官方飞信,ET飞信,爱短信飞信插件哪个好用??代发邮件我想做邮件代发,怎么做效果好?flash实例FLASH中实例是个什么概念,真心期待着!!!期待好心人,感恩!希望大家多讨论上行宽带上行宽带和下行宽带代表什么?cc防火墙服务器里安全狗里的WEB防火墙是什么意思android_secure内存卡上.android_secure是什么意思测试post什么是post 数据linux启动盘制作工具如何制作linux启动盘98系统98的系统怎么安?
免费域名申请 香港vps99idc mediafire下载 koss 外国域名 lighttpd gspeed 双11秒杀 广州服务器 空间技术网 hkt 爱奇艺vip免费领取 gtt 万网主机管理 智能dns解析 个人免费邮箱 服务器防火墙 789电视剧网 zcloud 美国asp空间 更多