Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于两侧icon的上下定位问题 #1

Open
paroquet opened this issue Apr 11, 2018 · 0 comments
Open

关于两侧icon的上下定位问题 #1

paroquet opened this issue Apr 11, 2018 · 0 comments

Comments

@paroquet
Copy link

paroquet commented Apr 11, 2018

你好!
现在有一种使用场景:允许edittext显示多行文本,即输入时可以换行输入,同时希望右边的删除图标紧贴输入框底线, 此时不指定android:inputType就可以换行,就像这样
default

随之而来的问题是, 现在希望右边的删除图标紧贴输入框底线,该如何实现?
我进行了尝试,将R.drawable.deletelayer-list包起来,并指定gravity

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap android:src="@drawable/delete"
            android:gravity="bottom"/>
    </item>
</layer-list>

并在edittext 的 setDeleteIconVisible(boolean deleteVisible,boolean leftVisible) 方法中给上面的drawable setBounds()来设置宽高,

 private void setDeleteIconVisible(boolean deleteVisible,boolean leftVisible) {
     if (ic_delete != null) {
         ic_delete.setBounds(0, 0, ic_delete.getIntrinsicWidth(), getMeasuredHeight());
     }
     setCompoundDrawables(leftVisible ?  ic_left_click :  ic_left_unclick, null,
             deleteVisible ?  ic_delete: null, null);
     color = leftVisible ? lineColor_click : lineColor_unclick;
     setTextColor(color);
     invalidate();
 }

此时删除图标的确会紧贴底线,但出现了新的问题,就是每输入一个字符,控件高度都在变高,getMeasuredHeight()总是在变大,
即使输入并没有换行。就像这样:
1

然后我就不知道该怎么办了...希望能获得帮助 : )

@paroquet paroquet changed the title 关于两侧侧icon的上下定位问题 关于两侧icon的上下定位问题 Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant