One bad effect of gallery menu sliding is that each menu that goes through the middle is selected by default, and the data is loaded so that the switching is not smooth. There is a feeling of kakaka !! In fact, the thread is used to solve this problem. If the selected index value remains unchanged after a certain period of time, it indicates that it has remained stable. The last part.Code!
// ---------------------- Used constant -----------------------------
Private int showingindex =-1;
Private Static final int time_out_display = 300;
Private int toshowindex = 0;
//--------------------------------------------------
// Process the selected event
Public void onitemselected (adapterview <?> Parent, view V, final int position,
Long ID ){
//--------------------------------------------------
Toshowindex = position;
Final handler = new handler (){
@ Override
Public void handlemessage (Message MSG ){
If (showingindex! = Toshowindex ){
Showingindex = toshowindex;
Menu_position = position;
// Process your business logic
}
}
};
Thread checkchange = new thread (){
@ Override
Public void run (){
Int myindex = toshowindex;
Try {
Sleep (time_out_display );
If (myindex = toshowindex ){
Handler. sendemptymessage (0 );
}
} Catch (interruptedexception e ){
E. printstacktrace ();
}
}
};
Checkchange. Start ();
}
OK, so that you can smoothly slide your components !! Basically, one card and one card won't happen!
Combined with titlegall. setcallbackduringfling (false);, you can create a sliding navigation bar at the top or bottom.