Saturday, September 17, 2011

[android-developers] Newbie Layout Help

Hey folkes, I need a bit of help with learning how to layout my app.  I'm fairly new to Android programming, and so far the most difficult aspect I have been finding is getting the layout for my app just the way I want it.  I'm after going through tutorials, video tutorials, etc, but I can't seem to figure out what I'm doing wrong here.  I'm sure its something basic.

First off, here is a drawing of how I would like my App to appear on a screen in standard vertical:

http://img37.imageshack.us/img37/7867/layoutiq.png

Now, a little bit of explanation:

- All my buttons have images for backgrounds, so they are all fixed size so it looks right
- The red and green boxes just groups together the widgets, but obviously doesn't appear on screen
- I would like my Header Image to stay at the top of the screen
- The elements btn2 and btn3 in the red box must stay at the bottom of the screen, with the btn3 being located to the top-right of btn2 and on the right-side of the screen.  And btn2 situated in the bottom-left of the screen.
- The elements btn1 and txt1 inside the green box should take up all space not being used between the header image and the red box.  Also, it must be center and near the top of the green box.

The current layout in my main.xml file almost gets the above right, except the red box pushes "up" causing the green box to shrink leaving space at the bottom of the screen.  I can't figure out how to fix that so it isn't pushing up.

Here is the code in my main.xml:


<?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"
    android:background="@drawable/bg"
    android:gravity="top">
    <LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="184px"
    android:gravity="top">
    <ImageView 
    android:layout_height="wrap_content" 
    android:src="@drawable/header" 
    android:layout_width="fill_parent" 
    android:id="@+id/imageView1">
    </ImageView>
    </LinearLayout>
    <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center">
    <Button 
    android:background="@drawable/btn1" 
    android:id="@+id/btn1" 
    android:layout_height="100dp" 
    android:layout_width="114dp">
    </Button>
    <TextView 
    android:gravity="center_horizontal" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:lines="2" 
    android:id="@+id/txt1">
    </TextView>
   
   
    </LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:
android:gravity="bottom">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom|left">
<Button 
android:id="@+id/btn2" 
android:background="@drawable/btn2" 
android:layout_height="176dp" 
android:layout_width="189dp">
</Button>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="2dp"
android:gravity="top|right">
<Button
android:background="@drawable/btn3"
android:id="@+id/btn3"
android:layout_height="88dp" android:layout_width="102dp">
</Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>


Keep in mind that I'm very new to this, so its probably something very obvious that I'm missing here.

Any help will be greatly appreciated.

Thank you.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment