I'm a newbie so sorry if the question is dumb! I have created a
Gallery, a baseAdapter and the Gallery is working fine. However I need
to find the coordinates ( in terms of the Gallery view )of each image
inside the Gallery when the user clicks on this image. Also most
importantly, I need to find out the coordinates of each ImageView in
terms of the whole screen, meaning the general coordinates

    public void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Gallery g1 = (Gallery) findViewById(R.id.gallery1);       //
creating gallery object 1
        g1.setAdapter(  new ImageAdapter(this)  );
        g1.setBackgroundColor(Color.BLUE);

        g1.setOnItemClickListener(
                        new OnItemClickListener()
                        {
                                public void onItemClick(AdapterView parent, 
View v, int
position, long id)
                                {
                                        /* here we get the coordinates of View 
'v' */
                                        int xCord = v.getRight();
                                        int yCord = v.getBottom();

                                        Toast.makeText(ImageGallery.this, 
"index: " + position +
" x coord: "+ xCord + " y coord: " + yCord,
Toast.LENGTH_SHORT).show();


                                } // end of method 'onItemClick'
                        } // end of internal anonymous class 
'OnItemClickListener'
                ); // end of 'setOnItemClickListener' call

}

/** 'ImageAdapter' class */
public class ImageAdapter extends BaseAdapter
{
       ......
       ......

        // an array of IDs that reference the images saved in the
drawable resources directory (res/drawable/)
        private Integer[] mImageIds =
        {
                //each image's size is 320x60
                        R.drawable.sample1,
                R.drawable.sample2,
                R.drawable.sample3,
                R.drawable.sample4,
                R.drawable.sample5,
                R.drawable.sample6,
                R.drawable.sample7
        };

        .......
        .......

        @Override
        public View getView(int position, View convertView, ViewGroup
parent)
        {
                // TODO Auto-generated method stub
                        // create a new object of type 'ImageView' using context
object called 'imageView1'
                    ImageView imageView1 = new ImageView(mContext);
                    // here we set the image by given its source from array
'mImageIds'
                    imageView1.setImageResource( mImageIds[position] );
                    // setting the Gallery.LayoutParams height and width for
the image
                    imageView1.setLayoutParams(new Gallery.LayoutParams( 300,
150 ));

        
imageView1.setScaleType(ImageView.ScaleType.CENTER_INSIDE );
                    /
*imageView1.setBackgroundResource(mGalleryItemBackground);*/

                    // here we return the image
                    return imageView1;
        }

-- 
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