I have a relative layout in my Android view.
I am trying to get the middle text to have some right padding or margin based on the EDIT icon. See below the image I'm going for.
However I can't seem to get the middle text to perform. It runs all the way up to the EDIT button.
What am I doing wrong here?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_height="30dp"
android:background="#26265e"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="14dp"
android:layout_height="14dp"
android:src="@drawable/ic_my_location_white_18dp"
android:layout_alignParentLeft="true"
android:adjustViewBounds="true"
android:ellipsize="middle"
android:layout_marginLeft="12dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dp"
/>
<TextView
android:id="@+id/tiLocationAddress"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:ellipsize="middle"
android:maxLines="1"
android:layout_marginBottom="7dp"
android:layout_marginLeft="30dp"
android:textSize="12dp"
/>
<TextView
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:textSize="13dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text="Edit"
android:onClick="onClick"
android:clickable="true"
/>
</RelativeLayout>
You need to say layout_toRightOf for your text view:
<TextView
android:id="@+id/tiLocationAddress"
//android:layout_alignParentLeft="true" - remove this
android:layout_toRightOf="@id/imageView1" - add this
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:ellipsize="middle"
android:maxLines="1"
android:layout_marginBottom="7dp"
android:layout_marginLeft="30dp"
android:textSize="12dp"
/>
I would recommend forcing the Edit Button or TextView to the End or Right, and then specifying that your other TextView to remain to the left of Edit. For that you will need to define an ID and reference it, like so:
<TextView
android:id="@+id/tiLocationAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rfnfjeknfwfwe welfmdlwekmklwemfklwemfw welmfweklmflwkmfwl"
android:textColor="#ffffff"
android:ellipsize="middle"
android:maxLines="1"
android:padding="5dp"
android:layout_centerVertical="true"
android:layout_marginBottom="7dp"
android:layout_marginLeft="30dp"
android:textSize="12dp"
android:layout_toLeftOf="@+id/btnEdit"
/>
<TextView
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:textSize="13dp"
android:id="@id/btnEdit"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text="Edit"
android:onClick="onClick"
android:clickable="true"
/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.