2 Replies - 8102 Views - Last Post: 06 March 2011 - 09:08 PM

#1 Medic873  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 16-November 08

Simple Image Viewer

Posted 03 March 2011 - 10:55 AM

Okay all I really want to do is have a program that will display a image on the users screen. Im not to sure how to this. I am fairly new to android and have been fallowing some of the tutorial I have found on youtube and on dic. But not to sure how to display a image yet.

I have done a basic hello world application but that is about as far as my programming skills with android has gone.

Also I am using motodev instead of eclipse I hate eclipse and motodev has really picked up the peices for me.

Is This A Good Question/Topic? 0
  • +

Replies To: Simple Image Viewer

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10396
  • View blog
  • Posts: 38,464
  • Joined: 27-December 08

Re: Simple Image Viewer

Posted 03 March 2011 - 11:02 AM

Moved to Android.

Take a look at the ImageView class.
Was This Post Helpful? 0
  • +
  • -

#3 kiwi_steve  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 109
  • Joined: 26-September 09

Re: Simple Image Viewer

Posted 06 March 2011 - 09:08 PM

View PostMedic873, on 04 March 2011 - 05:55 AM, said:

Okay all I really want to do is have a program that will display a image on the users screen.


I went through this a few days ago... its not too difficult, but I am not what you'd call an experienced programmer so hopefully this makes sense.

The image you need to display has to be copied to the res/drawable or res/drawable-hdpi folder so its available for use (I don't fully understand the hdpi, mdpi, ldpi structure other than its high, medium and low DPI, but I read somewhere that if you put a good quality pic in the hdpi folder then android will create the mdpi and ldpi ones as needed). I used a pic called gpig.jpg, so it shows up as R.drawable.gpig

The code (the last two lines are the important ones, along with the android.widget.ImageView import) is here:
package com.testexample.imagedisplayer;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

public class ImageDisplayer extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //create the imageview object
        ImageView iv = (ImageView) findViewById(R.id.imageView1);
        //set the image
        iv.setImageResource(R.drawable.gpig);
    }
}


and the main.xml needs an ImageView in it, something like this:
<?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" >
    
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" />
    
<ImageView 
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:id="@+id/imageView1"
	android:src="@drawable/icon"
	 />

</LinearLayout>


And that code gives you something that looks like:
Posted Image

Hope that helps

Steve

This post has been edited by kiwi_steve: 06 March 2011 - 09:13 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1