by marshac » Wed Apr 29, 2009 2:30 am
****Main.XML FILE******
I added the ImageView tag into my Main.XML File and made sure to use an id on this. Your android source must point to the name of the image.
<?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"
>
<ImageView id="@+id/splashscreen" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="@drawable/android_protype"
android:layout_gravity="center"/>
</LinearLayout>
*****HELLO IMAGE.Java File*********
I made the ImageView Object an private field and I cast the ImageView object to lookup the view by ID.
package com.android.example.protype;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class HelloImage extends Activity {
private ImageView splash;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
splash = (ImageView) findViewById(R.id.splashscreen);
}
}
Android Developer in Training