Hi,
I'm trying to create a preview effect on a Gallery view and
encountering issues with the Gallery.getChildAt(int position), which
is returning null most of the time. It's supposed to return null only
when the child is not displayed, which is not the case here, since the
user need to scroll over it.
Is there a way to solve this problem, or should I change my approach ?
Here is my code:

gallery.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
                if(event.getAction()==MotionEvent.ACTION_UP){
                        preview_container.setVisibility(View.GONE);
                }
                else if(event.getDownTime()>2500){
                        int position = 
gallery.pointToPosition((int)event.getX(),
(int)event.getY());
                        if (position!=AdapterView.INVALID_POSITION){
                                View child = gallery.getChildAt(position);
                                if(child!=null){
                                        Bitmap tmp_bitmap = 
book.imageForPreview(position);
                                        previewImg.setImageBitmap(tmp_bitmap);
                                        FrameLayout.LayoutParams layout = new
FrameLayout.LayoutParams(tmp_bitmap.getWidth()+2,
tmp_bitmap.getHeight()+2,Gravity.NO_GRAVITY);
                                        int[] coord = new int[2];
                                        child.getLocationOnScreen(coord);
                                        int y =
MMBookReader.this.getWindowManager().getDefaultDisplay().getHeight()-
(tmp_bitmap.getHeight()+view.getHeight());
                                        int x = (int) 
coord[0]-(tmp_bitmap.getWidth()-child.getWidth())/
2;
                                        layout.leftMargin=x;
                                        layout.topMargin=y;
                                        
preview_container.setVisibility(View.VISIBLE);
                                        
preview_container.setLayoutParams(layout);
        
previewPageCount.setText(book.getMmpages().get(position).getPosition()
+"/"+book.getPages());
                                }
                        }
                        else
                                preview_container.setVisibility(View.GONE);
                }
                return false;
                        }
                });

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to