Reputation: 982
I have recently started learning android. I am creating a layout which is something like
In the image: which i click on Button ,Text will get populated with some value And then i want the position of 2nd Text to be dynamically adjusted.
Currently both gets overlapped.
My XML file is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="2.5" >
<Button
android:id="@+id/get_address_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:onClick="getAddress"
android:text="@string/get_address" />
<TextView
android:id="@+id/label_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/get_address_button"
android:layout_marginTop="21dp"
android:text="@string/address"
android:textSize="12sp" />
<ProgressBar
android:id="@+id/address_progress"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/label_address"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:visibility="gone" />
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/label_address"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/label_address"
android:textIsSelectable="true"
android:textSize="20sp" />
<TextView
android:id="@+id/label_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/label_address"
android:layout_marginTop="21dp"
android:text="@string/distance"
android:textSize="12sp" />
<Spinner
android:id="@+id/location_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/label_distance"
android:layout_toRightOf="@+id/label_distance"
/>
</RelativeLayout>
Any help.
Thanks
Upvotes: 1
Views: 788
Reputation: 6925
Try this layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<Button
android:id="@+id/get_address_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:onClick="getAddress"
android:text="getAddress" />
<LinearLayout
android:id="@+id/text_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/get_address_button" >
<TextView
android:id="@+id/label_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="21dp"
android:text="Address
this is line 1
this is line 2
this is line 3
"
android:textSize="12sp" />
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/label_address"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/label_address"
android:textIsSelectable="true"
android:textSize="20sp" />
</LinearLayout>
<ProgressBar
android:id="@+id/address_progress"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/label_address"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:visibility="gone" />
<TextView
android:id="@+id/label_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/get_address_button"
android:layout_marginTop="21dp"
android:text="Distance"
android:textSize="12sp" />
<Spinner
android:id="@+id/location_spinner"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_below="@+id/text_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
Upvotes: 1
Reputation: 188
I m not sure where you want to position it,but if you want to position your 2nd text to the left/right/bottom/top then you can do something like this
1) take reference of your second Text View and and use yourTextView.setGravity(GRAVITY.LEFT/RIGHT/TOP/BOTTOM)
Upvotes: 0
Reputation: 438
Do it with RelativeLayout
, and the atribute android:below="@+id/idofyourmultilineedittext"
hope it helps
Upvotes: 0