問題描述
'android:paddingRight' 與 'android:drawableRight' 一起使用 (’android:paddingRight’ working with ‘android:drawableRight’)
In a EditText,I put a pic in the Rightside of the EditText, and I use FrameLayout to add a textview showing the remain input count of the Edittext(as show in p1).
But when the input is too long,it will overlay with the textview,to avoid this,I want use android:paddingRight to keep the input characters stay left,but the result is like p2
how to make the drawable icon stay at right and just the input characters ,like p3? Thank you.
‑‑‑‑‑
參考解法
方法 1:
You should use a RelativeLayout instead of appending the button after the text in a LinearLayout.
The resources for Android RelativeLayouts can be found at: http://developer.android.com/guide/topics/ui/layout/relative.html
That article is well worth a read
But the general principal is that you can define things like:
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/times" />
Note layout_below
and layout_toLeftOf
above, which define the positioning in relation to other objects
方法 2:
use ImageSpan for adding Image in EditView instead of Setting in Layout
方法 3:
This should be an alternative example, with RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_centerHorizontal="true"
android:paddingRight="30dp"
/>
<ImageView android:layout_width="20dp" android:layout_height="20dp"
android:src="@drawable/your_image"
android:layout_alignParentRight="true" android:layout_centerHorizontal="true"
/>
</RelativeLayout>
(by topxebec、biddulph.r、ρяσѕρєя K、Stefano Ortisi)