1package com.ename.views; 2 3import android.content.Context; 4import android.util.AttributeSet; 5import android.view.KeyEvent; 6import android.view.MotionEvent; 7import android.widget.Gallery; 8 9 10public class TopNewsGallery extends Gallery { 11 12 public TopNewsGallery(Context context) { 13 super(context); 14 } 15 16 public TopNewsGallery(Context context, AttributeSet attrs, int defStyle) { 17 super(context, attrs, defStyle); 18 } 19 20 public TopNewsGallery(Context context, AttributeSet attrs) { 21 super(context, attrs); 22 } 23 24 25 @Override 26 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 27 float velocityY) { 28 int kEvent; 29 if (isScrollingLeft(e1, e2)) { 30 // Check if scrolling left 31 kEvent = KeyEvent.KEYCODE_DPAD_LEFT; 32 } else { 33 // Otherwise scrolling right 34 kEvent = KeyEvent.KEYCODE_DPAD_RIGHT; 35 } 36 onKeyDown(kEvent, null); 37 return true; 38 } 39 private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) { 40 return e2.getX() > e1.getX(); 41 } 42 43}
Gallery实现流畅的新闻滚动 方法复写
Stella981
2021-10-11
1174 0 0
点赞
收藏
评论区
加载中...