简体   繁体   English

Android相对布局在对齐父对象时添加边距

[英]Android Relative Layout add Margin when Align Parent

I have a relative layout in my Android view. 我的Android视图中有相对布局。

I am trying to get the middle text to have some right padding or margin based on the EDIT icon. 我正在尝试使中间文本具有基于EDIT图标的一些右填充或边距。 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: 您需要为文本视图说layout_toRightOf:

<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. 我建议将“编辑按钮”或“ TextView”强制到“结尾”或“右边”,然后指定另一个TextView保留在“ Edit”的左边。 For that you will need to define an ID and reference it, like so: 为此,您将需要定义一个ID并引用它,如下所示:

<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"

        />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM