tags:

views:

48

answers:

1

Hi,

I'm new to android but I've been working my way through the tutoials. Still trying to get my head round layouts in a non-html world and was wondering how to achieve the following....

1) I'd like to set a tiled background to fill the screen behind the whole activity

2) I'd like to place a graphic and a button underneath it centred in the middle of the screen.

3) When the user clicks the button I'd like to start a new activity and presumably I have to do something to the current activity so the user can use the back button to get back to it.

Sorry for the newbie question.

Jon

+2  A: 
  1. Here's a tutorial on using a tiled background: http://androidblogger.blogspot.com/2009/01/how-to-have-tiled-background-cont.html

  2. I would use a combination of two containers (LinearLayouts probably) to achieve this. The outer container would have layout_width and layout_height to fill_parent to take up all available space and an android:gravity value of "center" to center the contents both horizontally and vertically. The inner one would have both params set to wrap_content to only take up the necessary space and an android:orientation value of "vertical" to layout out as you described. Then, add your image and button elements in the inner container.

  3. get a reference to the button in your activity class using findViewById (don't forget to add an android:id to the button in the xml), then on your reference to the Button element, add an OnClickListener that creates an Intent object representing the activity you want to launch and pass it to startActivity. I typically use this constructor (ie. new Intent(CurrentActivity.this, ActivityToLaunch.class)).

Look these things up. I could just give you code to copy and paste, but the learning sinks in if you have to put it together and fix some minor bugs on your own.

Rich
Thank Rich, you're a star. I'd rather learn than copy and past code.
jonhobbs