So I had the need to have an image displayed as a thumbnail kind of way. I wanted to be able to tap the image and have the larger version displayed.
This is how I have done it, for now. It is not ideal, it is not the complete answer to what I need but I learned a lot along the way in doing this.
1. Create the standard HelloWorld project
2. change your res/layout/main.xml to look like this:
java Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageButton
android:background="@null"
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="80px"
android:height="64px"
android:src="@drawable/myImagel" />
</LinearLayout>
android:width="80px" and android:height="64px" match the size of the image file myImage
android:background="@null" removes the button border making it look more like a free form image rather than a button
android:src="@drawable/myImage" assumes you have an image in your res/drawable folder named myImage, change this to any image of your choice
3. create the file res/layout/image.xml to look like this:
java Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/big_slide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myLargeImage" />
</LinearLayout>
android:src="@drawable/myLargeImage" assumes you have an image in your res/drawable folder named myLargeImage
4. make your src/HelloWorld.java file look like this
java Code:
package com.basil.HelloWorld;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.view.View.OnClickListener;
public class HelloWorld extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageButton imageButton = (ImageButton) findViewById(R.id.image);
imageButton.setOnClickListener(new OnClickListener() {
public void onClick
(View v
) { setContentView(R.layout.image);
}
});
}
}
This is not perfect as it just dumps the bigger image on the screen however it does demonstrate how to make an image clickable
hope it helps