Adding an image to your android project and adding buttons

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Adding an image to your android project and adding buttons

Postby marshac » Wed Apr 29, 2009 1:51 am

I was hoping if someone can post a tutorial on how to add an image to the android project and, once image is added show how we can add UI controls such as buttons, checkboxes, and editboxes on the image. I am a newbee to android and I wanted to know if this could be done. I looked at the splash screen tutorial that did not help me any. Any help on this would be gladly appreciated. :)
Android Developer in Training
marshac
Freshman
Freshman
 
Posts: 2
Joined: Fri Apr 17, 2009 8:11 pm
Location: Atlanta

Top

Fixed first problem-Adding images into Android project

Postby 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
marshac
Freshman
Freshman
 
Posts: 2
Joined: Fri Apr 17, 2009 8:11 pm
Location: Atlanta

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests