kaushal
kaushal

Reputation: 815

Question related to "Hello Gallery" Android Tutorial (How to display the image in full?)

I've implemented the Hello Gallery tutorial from the Android web:

http://developer.android.com/resources/tutorials/views/hello-gallery.html

The tutorial shows what happens when you select an image from the gallery - just display its position.

However, I also want to display the image in full size when an image is selected. Can someone tell how to do that?

Here's the code when an image is clicked:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Gallery g = (Gallery) findViewById(R.id.gallery);
    g.setAdapter(new ImageAdapter(this));

    g.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
           Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show();
        }
    });
 }

I unsuccessfully tried adding another 'ImageView' in main.xml, but it won't let me place that on the layout. May be because it's gallery layout?

Thanks.

Upvotes: 0

Views: 1046

Answers (2)

George
George

Reputation: 2200

In your onClick() you probably want to set the layout of the image to fill_parent with something like:

imageView.setLayoutParams(new Gallery.LayoutParams(
    ViewGroup.LayoutParams.FILL_PARENT,
    ViewGroup.LayoutParams.FILL_PARENT));

Upvotes: 2

Hassy31
Hassy31

Reputation: 2813

try this

i.setScaleType(ImageView.ScaleType.FIT_XY);

Upvotes: 2

Related Questions