I have checked a lot of Gallery methods on the Internet to stop listening to the location. They are all determined by starting a thread and then sleeping. I don't think it is necessary to open a thread, consume resources, and raise your hand.
When I accidentally saw the source code of the image library, I saw a piece of code, packages \ apps \ Gallery \ src \ com \ android \ camera \ ViewImage. java.
1
<Strong> private void scheduleDismissOnScreenControls (){
2
MHandler. removeCallbacks (mDismissOnScreenControlRunner );
3
MHandler. postDelayed (mDismissOnScreenControlRunner, 2000); // latency
4
5
} </Strong>
Combined with the OnItemSelectedListener of gallery, you can perform some operations after the sliding stop:
01
Class MyOnSelectLinstener implements OnItemSelectedListener {
02
@ Override
03
Public void onItemSelected (AdapterView <?> Parent, View view, int position, long id ){
04
ScheduleDismissOnScreenControls ();
05
}
06
Public void onNothingSelected (AdapterView <?> Parent ){
07
}
08
09
}
10
Private void scheduleDismissOnScreenControls (){
11
MHandler. removeCallbacks (mDismissOnScreenControlRunner );
12
MHandler. postDelayed (mDismissOnScreenControlRunner, 2000 );
13
}
Execute the operation in Runnable. When Gallery slides and switches pages, mHandler first deletes Runnable from the queue, so the operation is not executed, and then adds the delayed Runnable in the queue, if you do not flip the page again within the delay period, you can perform the Runnable operation here in gallery. When you drag the page, you can skip the Runnable method.
In this way, the listener can be stopped by sliding.
Author: dipper