Reputation: 188
I want to place a TextView
and an Editext
in same line but it may looks like TextView
is placing above EditText
. I've tried all solutions on SO but it didn't work for me exactly.
Here is my code
<RelativeLayout
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#ffffff"
android:text="From"
android:textColor="#000fff"
android:textStyle="bold" />
<EditText
android:id="@+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="right"
android:inputType="number"
android:visibility="invisible" />
</RelativeLayout>
It places the EditText
above TextView
.
Upvotes: 2
Views: 8846
Reputation: 1137
You can make use of the android:layout_weight
. You can view example here. The android:layout_weight
works only in Linearlayout
. You can also define a LinearLayout
inside the RelativeLayout
you've defined.
<LinearLayout
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/from"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".60"
android:layout_alignParentTop="true"
android:background="#ffffff"
android:text="From"
android:textColor="#000fff"
android:textStyle="bold" />
<EditText
android:id="@+id/input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".40"
android:layout_alignParentTop="true"
android:gravity="right"
android:inputType="number"
android:visibility="invisible" />
</LinearLayout>
Upvotes: 1
Reputation: 5574
Try using LinearLayout with horizontal orientation
<LinearLayout
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="From"
android:textColor="#000fff"
android:textStyle="bold" />
<EditText
android:id="@+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="right"
android:inputType="number"
/>
</LinearLayout>
Upvotes: 1
Reputation: 5152
its because you have given property fill_parent
to edit text,update it as this:
<EditText
android:id="@+id/input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="right"
android:inputType="number"
android:visibility="invisible"
android:layout_toRightOf="@id/from" />
Upvotes: 0
Reputation: 550
Can you check this solution
<TextView
android:id="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From"
android:textColor="#000fff"
android:textStyle="bold" />
<EditText
android:id="@+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="right"
android:inputType="number"
android:textColor="#ffffff"
android:text="sdjgsjgjb,,b,bm,m,sjksjkjjhks"
android:layout_toRightOf="@+id/from"
/>
Upvotes: 0