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. How can i make a menu, wich doesn't hide?

Hey Guys, i'm making my first app on Android.

I alredy made 3 Tabs, one with a list. I now want a menu to appear and
stay when I switch to this tab. the same for example on iphone in the
iPod, you always see the menu with title, interpret, lists etc. I
can't figure it out. May you please help me? thx!

This is the menu:

public boolean onCreateOptionsMenu(Menu menu) {
        menu.add("option 1");
        menu.add("option 2");
        menu.add("option 3");
        return super.onCreateOptionsMenu(menu);

}

-- 

2. surface manager, overlay

Hi,
Do we have any kind of documentation available for surface flinger and
overlays??

Thanks,
Deva

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. Oot ada androiders di jambi ga?

4. Accuracy in GPS Location

5. racoon service in Android init.rc

6. Activity design advice

7. Move the cursor to the end of EditText