15 Wallpaper 之OnTouch OnIntercept dispatch事件机制
来源:互联网 发布:回家吃饭网络订餐 编辑:程序博客网 时间:2024/06/06 04:46
--------------------------------mian.java------------------------
package com.example.gf;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
public class MainActivity extends ActionBarActivity {
private ListView lv1;
private ListView lv2;
private ListView lv3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv1 = (ListView) findViewById(R.id.lv1);
lv2 = (ListView) findViewById(R.id.lv2);
lv3 = (ListView) findViewById(R.id.lv3);
try {
lv1.setAdapter(new MyAdapter1());
lv2.setAdapter(new MyAdapter1());
lv3.setAdapter(new MyAdapter1());
} catch (Exception e) {
e.printStackTrace();
}
}
private int ids[] = new int[] { R.drawable.default1, R.drawable.girl1,
R.drawable.girl2, R.drawable.girl3 };
class MyAdapter1 extends BaseAdapter {
@Override
public int getCount() {
return 3000;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv = (ImageView) View.inflate(getApplicationContext(),
R.layout.lv_item, null);
int resId = (int) (Math.random() * 4);
iv.setImageResource(ids[resId]);
return iv;
}
}
}
-----------------------------MyLinerLayout.java----------------------
package com.example.gf;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
public class MyLinearLayout extends LinearLayout {
public MyLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int width=getWidth()/getChildCount();
int height = getHeight();
int count=getChildCount();
float eventX = event.getX();
if (eventX<width){// 滑动左边的 listView
// event.setLocation(width/2, event.getY()); 这句话没影响的,,,
getChildAt(0).dispatchTouchEvent(event);
return true;
} else if (eventX > width && eventX < 2 * width) { //滑动中间的 listView
float eventY = event.getY();
if (eventY < height / 2) {
// event.setLocation(width / 2, event.getY());
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
try {
child.dispatchTouchEvent(event);
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
} else if (eventY > height / 2) {
// event.setLocation(width / 2, event.getY());
try {
getChildAt(1).dispatchTouchEvent(event);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}else if (eventX>2*width){
event.setLocation(width/2, event.getY());
getChildAt(2).dispatchTouchEvent(event);
return true;
}
return true;
}
}
。。。。。。。。。。。。main.xml。。。。。。。。。。。。。。
<com.example.gf.MyLinearLayout 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:id="@+id/mll"
tools:context=".MainActivity" >
<ListView
android:id="@+id/lv2"
android:scrollbars="none"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ListView
android:id="@+id/lv1"
android:scrollbars="none"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ListView
android:id="@+id/lv3"
android:scrollbars="none"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</com.example.gf.MyLinearLayout>
。。。。。。。。。。。。。。lv_item.xml。。。。。。。。。。。。。
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/default1" />
- 15 Wallpaper 之OnTouch OnIntercept dispatch事件机制
- dispatch、onIntercept、onTouch三者对MotionEvent的分发、拦截机制分析
- dispatch onintercept
- Android事件传递机制之【onTouch方法】
- Android基础之onTouch事件传递机制
- Android事件机制之二:onTouch详解
- onTouch事件机制
- Android事件机制之二:onTouch详解 - Windstep
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- Android onTouch事件传递机制
- HDU 1016 - Prime Ring Problem [简单DFS]
- Letter Combinations of a Phone Number
- 《AngularJS权威教程》
- F - Flowers
- Android学习笔记の五
- 15 Wallpaper 之OnTouch OnIntercept dispatch事件机制
- Raising Modulo Numbers (poj 1995 快速幂水题)
- c和c++的一些训练题(9)(学生成绩管理系统)
- HDU 4549 M斐波那契数列(矩阵快速幂)
- poj 3185 The Water Bowls (高斯消元)
- 怎样在Linux启动后执行指定的命令
- WindowsHOOK编程
- 黑马程序员--java基础--语言基础部分
- Web高并发解决方案