Here is my layout
RelativeLayout
ImageView iv1
TextView
toTheRightOf iv1
toTheEndOf
It may be helpful. I did something like that, and in my solution I am scaling down textView, but you can set shorter text.
if(textView.getWidth() > 0) {
float widthOfTheText = textView.getPaint().measureText(textView.getText());
if(widthOfTheText > textView.getWidth()) {
//exceeds, let scale it
textView.setTextScaleX((textView.getWidth()-0.1f)/widthOfTheText);
} else {
//not exceeds
}
} else {
//not layouted yet
textView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
TextView tv = (TextView) v;
float widthOfTheText = tv.getPaint().measureText(tv.getText());
tv.setTextScaleX((tv.getWidth()-0.1f)/widthOfTheText);
tv.removeOnLayoutChangeListener(this);
if(widthOfTheText > tv.getWidth()) {
//exceeds, let scale it
tv.setTextScaleX((textView.getWidth()-0.1f)/widthOfTheText);
} else {
//not exceeds
}
}
});
}
Try this solution:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image1"
android:src="@android:drawable/ic_dialog_email"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dsajkhfkjhfasa fbsa fas fahj afs fsa afs sf afs sda da das dsals"
android:ellipsize="middle"
android:padding="10dp"
android:maxLines="1"
android:layout_toLeftOf="@+id/image2"
android:layout_toRightOf="@+id/image1" />
<ImageView
android:id="@+id/image2"
android:layout_alignParentRight="true"
android:src="@android:drawable/ic_dialog_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
In this layout, textview would ellipsize itself whenever the length would be greater than the available space.