Package gongzibai. co. cc;
Import android. content. Context;
Import android. util. AttributeSet;
Import android. view. KeyEvent;
Import android. view. MotionEvent;
Import android. widget. Gallery;
Public class DetialGallery extends
Gallery {
Public DetialGallery (
Context context,
AttributeSet attrs ){
Super (context, attrs );
// TODO Auto-generated constructor stub
}
Private boolean isScrollingLeft (
MotionEvent e1,
MotionEvent e2 ){
Return e2.getX ()> e1.getX ();
}
@ Override
Public boolean onFling (
MotionEvent e1,
MotionEvent e2,
Float velocityX,
Float velocityY ){
Int keyCode;
If (isScrollingLeft (e1, e2 )){
KeyCode = KeyEvent. KEYCODE_DPAD_LEFT;
} Else {
KeyCode = KeyEvent. KEYCODE_DPAD_RIGHT;
}
OnKeyDown (keyCode, null );
Return true;
}
}
------ Xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/widget32"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
<Gongzibai. co. cc. DetialGallery
Android: id = "@ + id/widget1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center"
Android: spacing = "10dp"/>
</LinearLayout>
By gongzibai