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. GIF or FLASH animated wallpaper for 2.1?

Hi! All.  can the new android 2.1 for the HTC nexus 1 support GIF,
Flash or MP4 animated wallpaper? If not, is there a tutorial or a user
interface program to create a live wallpaper out of a mp4 file?  I
don't need it to be responsive, just to be able to animate in the
background.  I have no experience in coding at all.  Would appreciate
assistance.

--

2. Google Gears on Android Simulator

I am testing a WebApp which uses Google Gears on Android Emulator.
When I access the page it fires a message that tells me that Google
Gears needs to be installed.

Q1: I thought Google Gears comes pre-installed on Android. Correct?

I click OK and I am redirected to the Google Gears site where I can
usually download the gears plug-in.
However, the website tells me that my browser is not supported by
Gears.

Q2. The Android browser doesnt support a plug-in developed by the same
company?

And Yes, I know that Google Gears is dead and that HTML5 is the way to
go. Does anyone have any information on how much of the HTML5 standard
the Android browser supports ?

Regards,

Alon

-- 

3. Using AJAX on Android

4. Problem with mediaplayer

5. Tips to write an app that fetches data from website and displays it on screen

6. Magic 32A Eclair 2.1 IM3 ga bisa Online gara2 Aktivasi Paket Data Internet.... [reg<spasi>mingguan kirim ke 323], ada Solusi

7. building android for imx51