• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps EditText help

mathkid95

Newbie
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>
 
First, you need to add an id to textview:
Code:
android:id=@+id/"TextView1"
then you have to add this code under EditText
Code:
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.
 
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:
<?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:layout_margin="5dip">
  
  	<View
	  android:layout_height="2dip"
	  android:layout_width="fill_parent"
	  android:background="#cceecc"
	  android:padding="5dip"
	/>
	
  	<TextView
  	  android:id="@+id/landowner_header"
  	  android:layout_width="wrap_content"
	  android:layout_height="wrap_content"
	  android:layout_gravity="left"
	  android:padding="5dip"
	  android:textSize="12dip"
	  android:text="Landowners Name:"
  	/>
  	
  	<EditText
	  android:id="@+id/landowner_edit"
	  android:layout_below="@id/landowner_header"
	  android:layout_width="fill_parent"
	  android:layout_height="40dip"
	  android:layout_gravity="left"
	  android:singleLine="true"
	  android:padding="5dip"
	  android:textSize="12dip"
	  android:hint="Landowners Name!"
	/>

</RelativeLayout>
 
Back
Top Bottom