Android Forums

Go Back   Android Forums > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
Reply
 
LinkBack Thread Tools Display Modes
Old 04-05-2009, 10:22 AM   #1
Junior Member
 
Join Date: Feb 2009
Posts: 10
Friends: 0
View droidan's Profile   View droidan's Photo Album   View droidan's Blog   View Social Groups
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:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:orientation="vertical"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent"
  6.     >
  7.                        
  8.     <ImageButton
  9.       android:background="@null"
  10.       android:id="@+id/image"
  11.       android:layout_width="wrap_content"
  12.       android:layout_height="wrap_content"
  13.       android:width="80px"
  14.       android:height="64px"
  15.       android:src="@drawable/myImagel" />
  16.                    
  17. </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:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:orientation="vertical"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent" >
  6.        
  7.     <ImageView
  8.         android:id="@+id/big_slide"
  9.         android:layout_width="wrap_content"
  10.         android:layout_height="wrap_content"
  11.         android:src="@drawable/myLargeImage" />
  12.        
  13. </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:
  1. package com.basil.HelloWorld;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.ImageButton;
  7.  
  8. import android.view.View.OnClickListener;
  9.  
  10. public class HelloWorld extends Activity {
  11.  
  12.     @Override
  13.     public void onCreate(Bundle savedInstanceState) {
  14.  
  15.         super.onCreate(savedInstanceState);
  16.        
  17.         setContentView(R.layout.main);
  18.  
  19.         final ImageButton imageButton = (ImageButton) findViewById(R.id.image);
  20.         imageButton.setOnClickListener(new OnClickListener() {
  21.             public void onClick(View v) {
  22.                 setContentView(R.layout.image);   
  23.             }
  24.         });
  25.        
  26.     }       
  27. }
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
droidan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Reply

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
ImageButton or what? droidan Android Development, Answers, Tutorials, and Code Snippets 1 04-05-2009 10:23 AM
Image Viewer / Zooming in Astro Creed Android Games And Applications 0 03-05-2009 07:27 AM
Image upload direct from G1 jabtas Android Chat 0 12-20-2008 04:22 AM
Android.jar of the SDK not open source? Autarkis Android Development, Answers, Tutorials, and Code Snippets 0 11-19-2008 05:59 AM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 09:42 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2008 TalkAndroid.com. All rights reserved.