如何在android中实现这种布局?
请看下面,我认为这应该是简单的,但我不能找出它 这样做的目的是使图像立即跟随某些文本,当文本很长时,图像仍然可以在那里,文本在末尾显示省略号。文本只有一行 谢谢如何在android中实现这种布局?,android,android-layout,Android,Android Layout,请看下面,我认为这应该是简单的,但我不能找出它 这样做的目的是使图像立即跟随某些文本,当文本很长时,图像仍然可以在那里,文本在末尾显示省略号。文本只有一行 谢谢 这应该是可行的: <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ABCABCABACBACBACBACBAC" a
这应该是可行的:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCABCABACBACBACBACBAC"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"
android:drawableRight ="@drawable/ic_info" />
试试这个安卓:ellipsize=end
在上面的评论中,您已经要求侦听器单击drawableRight上的事件,下面是该事件的实现
yourTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (event.getRawX() >= (yourTextView.getRight() - yourTextView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
return true;
}
}
return false;
}
});
非常感谢。我可以收听drawableRight的click事件吗?还有可能在触摸上增加涟漪效应?@Student222如果你需要听图标上的事件,可能你的方法是使用drawableright不是正确的答案,带有水平方向的线性布局以及内部TextView和imageView看起来应该是一样的,但工作方式是一样的want@Student222:你得到答案了吗?谢谢!我可以收听drawableRight的click事件吗?也许会在触摸屏上增加涟漪效应?你不能只在drawableRight上添加点击。如果需要,则需要单独添加图像。点击文本android:singleLine=true android:ellipsize=end android:drawableRight=@drawable/ic_info-在xml中使用这三行
yourTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (event.getRawX() >= (yourTextView.getRight() - yourTextView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
return true;
}
}
return false;
}
});