Android FrameLayout OnGestureListener手势操作
来源:互联网 发布:压缩包for mac 编辑:程序博客网 时间:2024/05/01 01:36
public class MyListView extends LinearLayout implements OnGestureListener {
private GestureDetector mGestureDetector;
private ListView mListView;
public MyListView(Context context) {
super(context);
mGestureDetector = new GestureDetector(this);
mListView = new ListView(context);
String[] items = createStrings();
mListView.setAdapter(new ArrayAdapter<String>(context,
android.R.layout.simple_list_item_single_choice, items));
mListView.setCacheColorHint(Color.TRANSPARENT);
mListView.setScrollBarStyle(SCROLLBARS_OUTSIDE_INSET);
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Log.i("info", "click");
}
});
this.addView(mListView, new LinearLayout.LayoutParams(350, LayoutParams.FILL_PARENT));
}
@Override
public boolean onDown(MotionEvent arg0) {
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
//empty
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
int scrollWidth = mListView.getWidth() - this.getWidth();
if ((this.getScrollX() >= 0) && (this.getScrollX() <= scrollWidth) && (scrollWidth > 0)) {
int moveX = (int)distanceX;
if (((moveX + this.getScrollX()) >= 0) && ((Math.abs(moveX) + Math.abs(this.getScrollX())) <= scrollWidth)) {
this.scrollBy(moveX, 0);
}
else {
if (distanceX >= 0) {
this.scrollBy(scrollWidth - Math.max(Math.abs(moveX), Math.abs(this.getScrollX())), 0);
}
else {
this.scrollBy(-Math.min(Math.abs(moveX), Math.abs(this.getScrollX())), 0);
}
}
}
return true;
}
@Override
public void onShowPress(MotionEvent e) {
//empty
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
mGestureDetector.onTouchEvent(ev);
super.dispatchTouchEvent(ev);
return true;
}
private String[] createStrings() {
return new String[] {
"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale",
"Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese",
"Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "Appenzell",
"Aragon", "Ardi Gasna", "Ardrahan", "Armenian String", "Aromes au Gene de Marc",
"Asadero", "Asiago", "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss",
"Babybel", "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal", "Banon",
"Barry's Bay Cheddar", "Basing", "Basket Cheese", "Bath Cheese", "Bavarian Bergkase",
"Baylough", "Beaufort", "Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese",
"Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir", "Bierkase", "Bishop Kennedy",
"Blarney", "Bleu d'Auvergne", "Bleu de Gex", "Bleu de Laqueuille",
"Bleu de Septmoncel", "Bleu Des Causses", "Blue", "Blue Castello", "Blue Rathgore",
"Blue Vein (Australian)", "Blue Vein Cheeses", "Bocconcini", "Bocconcini (Australian)",
"Boeren Leidenkaas", "Bonchester", "Bosworth", "Bougon", "Boule Du Roves",
"Boulette d'Avesnes", "Boursault", "Boursin", "Bouyssou", "Bra", "Braudostur",
"Breakfast Cheese", "Brebis du Lavort", "Brebis du Lochois", "Brebis du Puyfaucon",
"Bresse Bleu", "Brick", "Brie", "Brie de Meaux", "Brie de Melun", "Brillat-Savarin",
"Brin", "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)",
"Briquette de Brebis", "Briquette du Forez", "Broccio", "Broccio Demi-Affine",
"Brousse du Rove", "Bruder Basil", "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza",
"Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase", "Button (Innes)",
"Buxton Blue", "Cabecou", "Caboc", "Cabrales", "Cachaille", "Caciocavallo", "Caciotta"};
}
- Android FrameLayout OnGestureListener手势操作
- android 触摸手势 OnGestureListener
- Android OnGestureListener手势识别
- Android手势滑动GestureDetector和OnGestureListener(二)
- Android手势滑动GestureDetector和OnGestureListener(一)
- Android OnGestureListener 判断手势上下滑动
- 【安杰秀坊】-003- 手势操作OnGestureListener的复用实现
- Android OnGestureListener用法 识别用户手势 左右滑动
- Android OnGestureListener用法 识别用户手势 左右滑动
- GestureDetector.OnGestureListener 详解以及android手势动作详解!
- Android OnGestureListener用法 识别用户手势 上下左右滑动
- android ViewFlipper制作,OnGestureListener手势监听不灵敏问题
- android ViewFlipper制作,OnGestureListener手势监听不灵敏问题
- 用户检测手势Gesture implements android.view.GestureDetector.OnGestureListener
- Android中的手势识别器GestureDetector及OnGestureListener和SimpleOnGestureListener
- OnGestureListener的手势分析
- 利用OnGestureListener识别用户手势
- GestureDetector.OnGestureListener 触摸手势用法
- http下载中出现频繁断线,或者文件下载不完整,停滞。
- POJ_1659 Frogs' Neighborhood
- POJ_2553 求出度为0的强连通分支
- POJ_2186 Popular Cows
- 本土IC首次打入Apple供应链
- Android FrameLayout OnGestureListener手势操作
- Matlab 矩阵索引
- 黛玉传与红楼梦
- 如何在快速启动栏上添加东西?
- MATLAB矩阵索引 2
- Matlab 重塑和扩展矩阵
- 细说 BitmapData
- Out of memory问题总结
- 大音希声