Android Gallery - Replace Bitmap in ImageView after scrolling stopped
I've programmed a zoomable gallery with several images.
- The images can be zoomed.
- Zoomed images can be dragged.
- If the image is not zoomed, the gallery can be scrolled.
The layout consists of a LinearLayout
with a TextView
(the name of the gallery) and the Gallery
itself.
An item in the gallery consists of a RelativeLayout
containing a FrameLayout
with the ImageView
in it (I read I need the FrameLayout for zooming) and a TextView
to show the zoom state of the image.
I've used a custom View.OnTouchListener
to implement the zooming.
Now I was trying to replace the image in the ImageView
after the gallery has stopped scrolling with a high res picture so the user can zoom in much better/further.
I did this with the OnItemSelectedListener
and setCallbackDuringFling
to false.
Even this works fine if you fling the screen fast.
But if you keep your finger on the display and move it slowly to the edge, theOnItemSelectedListener
is fired before the next item reached the center and the sc开发者_开发技巧rolling animation stops. Instead the gallery jumps like it looses touch contact and centers the next item in the gallery immediately. Also the OnItemSelectedListener
is called more than once on the same item when moving the finger slowly (I avoid this problem by saving the position of the last selected item).
So (long story short) I was looking for a callback/listener to the "scrolling/snap-to-grid" effect of the Gallery
. I also tried an AnimationListener
, but the gallery returns null when i call getAnimation
on it.
I'm desperate here... can anyone help?
Problem solved: I'm now using the android.support.v4.view.ViewPager
with the custom callbacks in the OnPageChangeListener
:
onPageSelected
onPageScrollStateChanged
onPageScrolled
I recommend a slight change to your method. For your Gallery, override onScroll(MotionEvent, MotionEvent, float, float)
and onFling(MotionEvent, MotionEvent, float, float)
have them return their super but on MotionEvent.ACTION_DOWN || MotionEvent.ACTION_UP set a moving flag to true || false respectively.
Now in the BaseAdapter for your Gallery in the getView(int, View, ViewGroup) method when you are returning your image view return the low res ImageView if the moving flag is true else return the high res.
精彩评论