文本视图行 - 建议
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最好也是最简单的方法是将名称设置为保留在第二张图像的左侧。
The best and easiest way is to set the name to stay at the left of the second image.
您可以限制 TextView 的最大宽度:
android:maxWidth="10dp"
You can bound the max width of your TextView:
android:maxWidth="10dp"
给出文本视图的大小,如 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.
您可以利用此功能,
如果您的文本超出了文本视图的宽度,则“...”点将附加在末尾。
如果上面的代码不起作用添加 android:singleLine="true"
You can make use of this
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"