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. Different transparency support on diff devices!?

I've got Superpad 3 android tablet with 2.2 on board, and I'm
developing my apps on it, but recently got stupid bug dnt know how to
fix..bug is:
It doesn't show transparent elements above video eq SurfaceView or
VideoView, just greyscale region depends transperancy percentage. On
my HTC Hero same elements handles fine. Where is the problem and how
can I fix it!? Thanks

-- 

2. Changing application description shown in option list when multiple apps can do same job

Hello there,

I have a viewer app. There are other apps installed on my device as
well doing same job. So when i open a document, android as usual shows
a list of apps that can do that job (which is file open here).

In my app, along with App name, just beneath it, package name gets
displayed. I want to set App description instead of package name. I
tried with
 <application android:description="@string/app_description">

its not working. Where to set this custom string ?

-- 

3. MediaPlayer blocked(AudioFlinger write blocked) while playing animation

4. How to close all activities on android app

5. TransitionDrawable with different sized bitmaps

6. Saving an image

7. how to give effects to livewallpaper?