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. where is sleep/screen behavior documented?

Hi Richard, sorry I really don't have time to go into detail on this stuff
at this point (and don't personally know enough to cover everything
anyway).  Ultimately the source code -- in particular PowerManagerService
and the keyguard interactions as start in PhoneWindowManager -- is the
ultimate specification, and these things change over time (for example in
Eclair the press menu to unlock behavior will be different at least on some
class of devices).  And many parts of this are intended to be fairly easy to
customize by a manufacturer to work most appropriately for their device.

Finally, this really sounds like the discussion should be on
android-porting; this doesn't look like stuff that is relevant to third
party developers.

On Mon, Oct 5, 2009 at 2:21 PM, Richard Schilling <









-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

2. When Softkeyboard in emulator appears, EditText view donot scroll up

Hi,

I have a query. With SDK 1.5, I have a editText box at the very end of
the screen in potrait mode. So when I click on this edittext box, the
soft keyboard appears and the view should scroll up so that the user
can see the cursor in editbox to type in. But with me as the view
donot scroll up.

My .xml layout is as follows:
<AbsoluteLayout >
   <TextView/>
   <FrameLayout>
      <ListView/>
   </FrameLayout>
   <EditText />
   <Button/>
</AbsoluteLayout >

Can anyone please help me out how can I make the view scroll by itself
when the soft keyboard appears?

Thanks.
Regards,
Purvi

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

3. set default APN programmatically

4. HelloMapView Tutorial not working

5. access to data from the rtsp stream

6. Android communication

7. Wake Locks and the Cellular antenna...