textView lines - advice

删除回忆录丶 提交于 2019-12-04 06:41:20

问题


<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.


回答1:


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




回答2:


You can bound the max width of your TextView:

android:maxWidth="10dp"




回答3:


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




回答4:


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"



来源:https://stackoverflow.com/questions/8443220/textview-lines-advice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!