Such as AD control requirements
Display an image at a time
Only one slide can be made at a time.
Automatic playback
/**
* The image gallery can only slide one image at a time.
* @ Author CMM
* @ Date 2012-02-02
* @ Version 1.0
*/
Public class imagegallery extends gallery {
Public imagegallery (context, attributeset paramattributeset ){
Super (context, paramattributeset );
}
@ Override
Public Boolean onfling (motionevent parammotionevent1,
Motionevent parammotionevent2, float paramfloat1, float paramfloat2 ){
Return false;
}
@ Override
Public Boolean onscroll (motionevent parammotionevent1, motionevent parammotionevent2, float paramfloat1, float paramfloat2 ){
Float F = 1.4f * paramfloat1;
Return super. onscroll (parammotionevent1, parammotionevent2, F, paramfloat2 );
} Http://www.eoeandroid.com/thread-102526-1-1.html
@ Override
Protected Boolean getchildstatictransformation (view child, transformation T ){
Return true;
}
}
<? XML version = "1.0" encoding = "UTF-8"?>
<! -- Advertisement item -->
<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
<Imageview
Android: Id = "@ + ID/qianghaoqi_ad_item_image"
Android: layout_width = "fill_parent"
Android: layout_height = "30020.dip"
Android: paddingbottom = "2020.dip"
Android: paddingleft = "2020.dip"
Android: paddingright = "2020.dip"
Android: paddingtop = "28w.dip"
Android: scaletype = "fitxy"/>
</Relativelayout>
/**
* Auto-scrolling playback is mainly implemented by combining timer and handler. Timer is responsible for generating and transmitting scheduled update messages,
* The handler receives the processed message and resets the currently displayed image.
*/
Final handler mautogalleryhandler = new handler (){
Public void handlemessage (message ){
Super. handlemessage (Message );
Switch (message. What ){
Case handlertypeutils. handler_type_load_data_main_gallery_pos:
Mimagegallery. setselection (message. getdata (). getint (
Constantutil. gallery_pos ));
Break;
}
}
};
Timer mautotimer;
/**
* Timer is responsible for regularly updating the generation and transmission of messages. After adelay seconds, information is sent every aperiod seconds.
*
* @ Param adelay
* @ Param aperiod
*/
Protected void settimer (long adelay, long aperiod, final int APOs ){
If (mautotimer! = NULL ){
Mautotimer. Cancel ();
}
Mautotimer = new timer ();
Mautotimer. Schedule (New timertask (){
Int gallerypisition = apos;
@ Override
Public void run (){
If (gallerypisition <mcount-1 ){
Gallerypisition = gallerypisition + 1;
} Else {
Gallerypisition = 0;
}
Message MSG = new message ();
Bundle date = new bundle (); // store data
Date. putint (constantutil. gallery_pos, gallerypisition );
MSG. setdata (date );
MSG. What = handlertypeutils. handler_type_load_data_main_gallery_pos; // Message ID
Mautogalleryhandler. sendmessage (MSG );
}
}, Adelay, aperiod); // after 5 seconds, the message is sent every 5 seconds.
}
<! -- Homepage advertisement -->
<Framelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Xmlns: MySpace = "http://schemas.android.com/apk/res/com.blade.qianghaoqi"
Android: Id = "@ + ID/qianghaoqi_ad_layout"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "vertical">
<Com. Blade. qianghaoqi. UI. uicommon. baseview. imagegallery
Android: Id = "@ + ID/qianghaoqi_ad_gallery"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: animationduration = "100"
Android: fadingedge = "NONE"
Android: spacing = "0.0dip"/>
<! -- Add a flag -->
<Linearlayout
Android: Id = "@ + ID/qianghaoqi_ad_position"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_gravity = "bottom | Center"
Android: Orientation = "horizontal"
Android: paddingbottom = "5.0dip">
</Linearlayout>
</Framelayout>
/**
* Load a flag point
*/
Protected void loadpositionimage (){
Imageview aimageview = NULL;
Mlinearlayout. removeallviews ();
For (INT I = 0; I <mcount; I ++ ){
Aimageview = new imageview (this );
If (I = 0 ){
Aimageview
. Setimageresource (R. drawable. game_blade_qianghaoqi_alert_dialog_help_selected );
} Else {
Aimageview
. Setimageresource (R. drawable. game_blade_qianghaoqi_alert_dialog_help_unselected );
}
Mlinearlayout. addview (aimageview );
}
}
/**
* Change the flag point status
*
* @ Param APOs
*/
Public void changepositionimage (INT APOs ){
Imageview aimageview = (imageview) mlinearlayout. getchildat (APOs );
If (aimageview! = NULL ){
Aimageview
. Setimageresource (R. drawable. game_blade_qianghaoqi_alert_dialog_help_selected );
}
For (INT I = 0; I <mcount; I ++ ){
If (I! = APOs ){
Aimageview = (imageview) mlinearlayout. getchildat (I );
Aimageview
. Setimageresource (R. drawable. game_blade_qianghaoqi_alert_dialog_help_unselected );
}
}
}
@ Override
Public void onitemselected (adapterview <?> Parent, view, int position,
Long ID ){
Changepositionimage (position );
Setactionaddata (position );
}
From: http://mmandroid.diandian.com/post/2012-02-27/16773046
Niu Ren blog Space