Image won't display

by guysmily » Tue, 13 May 2008 02:42:17 GMT


Sponsored Links
 I simply want to display an image. I can't seem to get it working.
What am I missing?

Java code:

package com.android.hello;

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


public class MYNEWCLASS extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle icicle) {
       super.onCreate(icicle);
       TextView tv = new TextView(this);
       tv.setText("Welcome to my screen");
       setContentView(tv);


       ImageView image =new ImageView(this);
 
image.setImageDrawable(getResources().getDrawable(R.drawable.button_image));

       image.setScaleType(ImageView.ScaleType.FIT_CENTER);
       image.setAdjustViewBounds(true);
       /*
       image.setMaxHeight(10);
       image.setMaxWidth(10);
       */
   }
}

The main.xml 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"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Welcome to my screen"
    />
<ImageView id="@+android:id/image"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:layout_width ="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/button_image"
    android:layout_x="91px"
    android:layout_y="179px"
    />

</LinearLayout>

I have button_image.png saved in the res/drawable directory.

Any ideas?
--~--~---------~--~----~------------~-------~--~----~



Image won't display

by Mark Murphy » Tue, 13 May 2008 12:06:05 GMT


 


You are calling setContentView(tv) to set the activity's view to be a 
dynamically-created TextView. If you want to use your layout, you need 
to call setContentView(R.layout.main).

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
The Busy Coder's Guide to Android Development -- coming in June 2008!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Image won't display

by guysmily » Wed, 14 May 2008 02:09:08 GMT


 Thanks Mark, that was it.






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Using raw resource sound file as Ringtone

I have a problem setting a ringtone from a resource in my app:

Uri uri = Uri.parse("android.resource://com.package.app/" +
R.raw.sound1);
RingtoneManager.setActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_RINGTONE, uri);

I've noticed also some people had the same problem but got no answers.
Do any of you guys have any idea of how making this work? (without
having to copy the file to the sdcard)

Cheers

-- 

2. Anyway to check if any items on the history/activity stack?

Hi,

I'm trying to figure out if there's any way to see if there is
anything on the history stack so I can programatically display a Back
button or not.

I tried getting the RunningTaskInfo to get the num of activities but
it doesn't seem to work quite right for what I need. Does anyone know
of another way?

Sammy

-- 

3. Can anyone tell me ONE app that shows up in Android Market on HTC Tattoo

4. Help! How to create tiled drawable from xml? (Poor documentation of this on the official developer site)

5. How to get all contact's name phone number, email for 2.0

6. Why is "LABEL" an invalid column for a ContactMethod?

7. Is the Drawable.createFromStream(..) thread-safe?