<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.
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" />
You can bound the max width of your TextView:
android:maxWidth="10dp"
Give the size of textview like android:layout_width="xdp" and android:maxLines="2" or whatever you want.
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