向右移动文本以在EditText中为按钮留出空间。可能?

时间:2013-02-06 03:24:07

标签: java android user-interface textview android-edittext

这与我想要达到的目标类似(见图)。我有删除按钮(在右侧)工作,所以我知道如何添加按钮。但是,如何移动文本以留出左侧按钮的空间?

enter image description here

1 个答案:

答案 0 :(得分:1)

你可以做这样的事情

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="center_vertical" >

        <EditText
            android:id="@+id/editText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="30dp"
            android:paddingRight="30dp" />

        <ImageView
            android:id="@+id/leftImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="5dp"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/rightImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginRight="5dp"
            android:src="@drawable/ic_launcher" />
    </RelativeLayout>

</RelativeLayout>

您可以使用按钮或任何其他视图代替ImageView。还可以根据需要调整边距和填充。