Results 1 to 2 of 2

Thread: Layout problems

  1. #1
    cfc1252 is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default Layout problems

    I want to display the following:

    TextView
    EditView
    2 x Button
    TextView

    This is the code I have:

    Java Code:
    <?xml version="1.0" encoding="utf-8"?>   
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Type here:"/>
        <EditText
            android:id="@+id/entry"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background"
            android:layout_below="@id/label"/>
        <Button
            android:id="@+id/ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/entry"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10dip"
            android:text="OK" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/ok"
            android:layout_alignTop="@id/ok"
            android:text="Cancel" />
         <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    </RelativeLayout>
    The last TextView doesn't show up. Any ideas why?

  2. #2
    Kyle227's Avatar
    Kyle227 is offline Member
    Join Date
    Apr 2010
    Location
    Mass
    Posts
    47
    Rep Power
    0

    Default Re: Layout problems

    So you want a layout like this? Don't mind the title :P

    Layout problems-screenshot-2012-02-19-15-19-28.png

    Well that was all using LinearLayouts and it was very easy. The root layout is a LinearLayout (horizontal) and the next two down are LinearLayouts (Vertical) with some padding and weights added. Then the last item is your TextView. You can customize it anyway you want but you don't have to use Relative Layouts all the time.

    Java Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="false" >
    
            <TextView
                android:id="@+id/label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="10dp"
                android:text="Type here:" />
    
            <EditText
                android:id="@+id/entry"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:drawable/editbox_background" >
    
            </EditText>
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <Button
                android:id="@+id/ok"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="OK" />
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Cancel" />
        </LinearLayout>
    
        <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
    </LinearLayout>
    Last edited by Kyle227; 02-19-2012 at 09:38 PM.

Similar Threads

  1. GUI Layout problems.
    By Vampiricx3 in forum AWT / Swing
    Replies: 1
    Last Post: 02-04-2012, 04:52 AM
  2. JAVA GUI Layout problems...
    By arcelivez in forum AWT / Swing
    Replies: 1
    Last Post: 11-25-2011, 01:48 AM
  3. Replies: 13
    Last Post: 12-06-2010, 05:57 AM
  4. Keyboard Layout Problems
    By FrederikNS in forum Eclipse
    Replies: 0
    Last Post: 10-28-2008, 04:03 PM
  5. JPanel / layout problems
    By Warhorsei in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2008, 05:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •