当前位置: 首页 > news >正文

长春市住房和城乡建设局网站/电工培训技术学校

长春市住房和城乡建设局网站,电工培训技术学校,原有网站已备案 怎么做接入,dw网页制作教程动态更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 本篇文章自定义ViewGroup实现瀑布流效果来进行详解dispatchTouchEvent ----- onInterceptTouchEvent----- onTouchEvent 最外层的ViewGroup首先接收到触摸事件,然后遍历他…

更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680
本篇文章自定义ViewGroup实现瀑布流效果来进行详解
dispatchTouchEvent ----- onInterceptTouchEvent----- onTouchEvent

最外层的ViewGroup首先接收到触摸事件,然后遍历他的子View或者ViewGroup,将触摸时间分发给包含触摸位置的子View,继续下去,直到该事件被消费(1.某个View的onTouchEvent返回了true;2.设置了监听并返回了true。这样该View的dispatchTouchEvent也就返回了true即事件被该View消费)onInterceptTouchEvent会拦截事件往下层传递,即中断事件传到子View,会执行自己的onTouchEvent。

下面的效果以前看到过,实现的思路挺不错的,算是对事件分发这些知识的实战吧。

19956127-2cfaaadaae1c2d6b.png

在第一个listview里面上下滑动,由第一个listview分发事件。

在第二个listview里面上面滑动,三个listview均分发事件,实现一次触摸的联动效果。

在第二个listview里面的下面上下滑动,由第二个listview分发事件。

在第三个listview里面上下滑动,由第三个listview分发事件。

继承LinearLayot,拦截触摸事件,由自己重新分发。

public boolean onInterceptTouchEvent(MotionEvent ev) {return true;}
public boolean onTouchEvent(MotionEvent event) {width = getWidth();eventX = (int) event.getX();childWidth = width / getChildCount();if (eventX < childWidth) {// 第一列的listviewevent.setLocation(childWidth/2, event.getY());getChildAt(0).dispatchTouchEvent(event);}else if (eventX >childWidth && eventX < 2*childWidth) {// 第二列的listviewevent.setLocation(childWidth/2, event.getY());if (event.getY() < getHeight()/2) {// 第二列的listview上面// 三个listview联动for(int i = 0; i < getChildCount(); i++){getChildAt(i).dispatchTouchEvent(event);}}else {// 第二列的listview下面getChildAt(1).dispatchTouchEvent(event);}}else {//第三列listviewevent.setLocation(childWidth/2, event.getY());getChildAt(2).dispatchTouchEvent(event);}   return super.onTouchEvent(event);}

布局文件:

<com.example.day150214_pullstream.MyLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:clickable="true" ><ListView android:id="@+id/lv1"android:layout_height="match_parent"android:layout_width="0dp"android:layout_weight="1"/><ListView android:id="@+id/lv2"android:layout_height="match_parent"android:layout_width="0dp"android:layout_weight="1"/><ListView android:id="@+id/lv3"android:layout_height="match_parent"android:layout_width="0dp"android:layout_weight="1"/></com.example.day150214_pullstream.MyLayout>

MainActivity:

protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initList();adapter = new SimpleAdapter(this, list, R.layout.item, new String[]{"iv"}, new int[]{R.id.iv});lv1 = (ListView) findViewById(R.id.lv1);lv2 = (ListView) findViewById(R.id.lv2);lv3 = (ListView) findViewById(R.id.lv3);lv1.setAdapter(adapter);lv2.setAdapter(adapter);lv3.setAdapter(adapter);}private void initList() {for (int i = 0; i < 20; i++) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("iv", R.drawable.ic_launcher);list.add(map);}}

更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680

http://www.jmfq.cn/news/4779037.html

相关文章:

  • 网站建设包括哪些部分/网络营销外包收费
  • 合肥最新消息/seo技巧是什么
  • 河北网站建设口碑好/附近学电脑培训班
  • 网站风格设计怎么写/seo项目经理
  • 上海知名网站制作公司/口碑营销案例2021
  • 衡水做网站的公司/品牌营销策划机构
  • 百度竞价排名是什么意思/seo推广主要做什么的
  • 北京泵网站建设/网站推广优化技巧
  • 门户网站域名是什么/windows优化大师软件介绍
  • 做废钢推广网站/seo优化培训多少钱
  • 城乡建设部网站自助商品房/惠州百度seo排名
  • 富顺住房和城乡建设厅网站/线下推广都有什么方式
  • 在网站上卖东西怎么做/成都网站优化公司
  • 网站开发与应用/全球网站排行榜
  • 西宁网站建设/关键词排名靠前
  • 建设路84号 网站备案/网站的seo是什么意思
  • 网站建设大致价格2017/百度sem认证
  • 湖南专业做网站公司/百度收录网站链接入口
  • PHP做克隆网站/推广费用一般多少
  • aspcms手机网站插件/门户网站
  • 在哪里找做网站的/今日热搜榜前十名
  • 把开发的网站让外网能访问要怎么做/微营销推广方案
  • 做义工的靠谱网站/百度收录怎么查询
  • 学院网站建设需求分析调研表/花都网站建设公司
  • 怎么在Front做网站/郑州seo排名哪有
  • 官方网站怎样做/加拿大搜索引擎
  • 做行程规划的旅行网站/百度指数可以用来干什么
  • WordPress 布局 企业网站/北京官网seo
  • 郑州西区做网站/网络营销推广策划步骤
  • 天长做网站的/付费推广