文本视图行 - 建议

发布于 2024-12-20 03:54:37 字数 1318 浏览 2 评论 0原文

<RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:adjustViewBounds="true"
            android:src="@drawable/icon" />

        <TextView
            android:id="@+id/fullnameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/wayimageView"
            android:textColor="@color/list_text_color"
            android:textSize="16dp"
            android:singleLine="false"
             />
    <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:adjustViewBounds="true"
            android:src="@drawable/icon" />
    </RelativeLayout>

我想将名称设置为 imageView 的右侧。很好,但有一个问题。当名称太长时,它将位于第二个图像视图下。有没有办法给textView的行最大字符数(例如10),当字符大小为10时,它会自动转到第二行。

<RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:adjustViewBounds="true"
            android:src="@drawable/icon" />

        <TextView
            android:id="@+id/fullnameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/wayimageView"
            android:textColor="@color/list_text_color"
            android:textSize="16dp"
            android:singleLine="false"
             />
    <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:adjustViewBounds="true"
            android:src="@drawable/icon" />
    </RelativeLayout>

I want set name to right of imageView. It's fine but there is one problem. When the name is too long it's going under the second imageview. Is there a way to give textView's line maximum charachters count (e.g. 10) when the chars size is 10 it's automatically go to second line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

愁以何悠 2024-12-27 03:54:37

最好也是最简单的方法是将名称设置为保留在第二张图像的左侧。

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="10dp"
    android:adjustViewBounds="true"
    android:src="@drawable/icon" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentright="true"
    android:layout_marginRight="10dp"
    android:adjustViewBounds="true"
    android:src="@drawable/icon" />

<TextView
    android:id="@+id/fullnameTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/imageView2"
    android:layout_toRightOf="+@id/wayimageView"
    android:textColor="@color/list_text_color"
    android:textSize="16dp" />

The best and easiest way is to set the name to stay at the left of the second image.

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="10dp"
    android:adjustViewBounds="true"
    android:src="@drawable/icon" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentright="true"
    android:layout_marginRight="10dp"
    android:adjustViewBounds="true"
    android:src="@drawable/icon" />

<TextView
    android:id="@+id/fullnameTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/imageView2"
    android:layout_toRightOf="+@id/wayimageView"
    android:textColor="@color/list_text_color"
    android:textSize="16dp" />

淡笑忘祈一世凡恋 2024-12-27 03:54:37

您可以限制 TextView 的最大宽度:

android:maxWidth="10dp"

You can bound the max width of your TextView:

android:maxWidth="10dp"

凡间太子 2024-12-27 03:54:37

给出文本视图的大小,如 android:layout_width="xdp" 和 android:maxLines="2" 或任何你想要的。

Give the size of textview like android:layout_width="xdp" and android:maxLines="2" or whatever you want.

自演自醉 2024-12-27 03:54:37

您可以利用此功能,

    android:ellipsize="end" 
    android:maxLines="1"
    android:scrollHorizontally="true"

如果您的文本超出了文本视图的宽度,则“...”点将附加在末尾。

如果上面的代码不起作用添加 android:singleLine="true"

You can make use of this

    android:ellipsize="end" 
    android:maxLines="1"
    android:scrollHorizontally="true"

If your text goes out of textview's width then "..." dots will be appended at the end.

If above code not working add android:singleLine="true"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文