如何在android中实现这种布局?

时间:2016-09-20 03:51:37

标签: android android-layout

请看下面,我认为这应该很简单,但我无法弄明白......

目标是使图像立即跟随某些文本,当文本很长时,图像仍然存在,文本末尾显示省略号。文字只有一行。

谢谢!

enter image description here

3 个答案:

答案 0 :(得分:3)

这件事应该有效:

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

答案 1 :(得分:0)

试试这个android:ellipsize="end"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableEnd="@drawable/images"
        android:ellipsize="end"
        android:maxLines="1"
        android:text="Large Text fgkjdsfgkjdfslgk jdsfg jdfgjdfjgijdfogjdfgdfsgdfsg dfsg  dfsg sdf g"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableEnd="@drawable/images"
        android:ellipsize="end"
        android:maxLines="1"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

答案 2 :(得分:0)

在上面的评论中,你已经要求听众在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;
                }

        });