1. Check out our companion app, Forums for Android! Download from Google Play

EditText help

Discussion in 'Application Development' started by mathkid95, Dec 24, 2010.

  1. mathkid95

    mathkid95 Member
    Thread Starter
    15

    May 29, 2010
    21
    0
    15
    Hi,

    I wanted to know how to change the location of an EditText input box. I have some Text to be shown on top, then I want the EditText box to be underneath the text, and in the bottom center of the screen. I've tried using gravity, layout gravity, width, height, margins, and I just can't get it to work. I've also tried changing this to a LinearLayout, which totally got rid of the edittext.

    Here is the xml:


    <?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"
    android:background="#000033">


    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="15dp"
    android:text="\nHello!"
    android:gravity="center_vertical"
    android:typeface="serif"
    android:textSize="15sp"
    android:textColor="#993300"
    android:textStyle="bold"
    />


    <EditText

    android:text=""
    android:id="@+id/EditText01"
    android:layout_height="60px"
    android:layout_width="40px"
    android:inputType="number"
    android:singleLine="True"
    android:layout_gravity="bottom"

    />



    </RelativeLayout>
     

    Advertisement

  2. hyungjungsoh

    hyungjungsoh Member
    16

    Nov 7, 2010
    18
    1
    16
    &#45224;&#54620;
    First, you need to add an id to textview:
    Code (Text):
    1. android:id=@+id/"TextView1"
    then you have to add this code under EditText
    Code (Text):
    1. android:layout_below="@id/TextView1"
    XD I haven't really tested this, but as far as I can remember, this is what I did before. android:below: will put the EditText below the TextView. XD This will only work on Relative Layout though.
     
  3. JamTheMan

    JamTheMan Well-Known Member
    38

    As mentioned it should be working with the relative layout, ID's and android:layout_below. Here's an example from one of my previous apps:

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <RelativeLayout
    3.   xmlns:android="http://schemas.android.com/apk/res/android"
    4.   android:layout_width="fill_parent"
    5.   android:layout_height="fill_parent"
    6.   android:layout_margin="5dip">
    7.  
    8.     <View
    9.       android:layout_height="2dip"
    10.       android:layout_width="fill_parent"
    11.       android:background="#cceecc"
    12.       android:padding="5dip"
    13.     />
    14.    
    15.     <TextView
    16.       android:id="@+id/landowner_header"
    17.       android:layout_width="wrap_content"
    18.       android:layout_height="wrap_content"
    19.       android:layout_gravity="left"
    20.       android:padding="5dip"
    21.       android:textSize="12dip"
    22.       android:text="Landowners Name:"
    23.     />
    24.    
    25.     <EditText
    26.       android:id="@+id/landowner_edit"
    27.       android:layout_below="@id/landowner_header"
    28.       android:layout_width="fill_parent"
    29.       android:layout_height="40dip"
    30.       android:layout_gravity="left"
    31.       android:singleLine="true"
    32.       android:padding="5dip"
    33.       android:textSize="12dip"
    34.       android:hint="Landowners Name!"
    35.     />
    36.  
    37. </RelativeLayout>
     

Share This Page

Loading...