I do not think you can do this using just the layout. For Android to ellipse Text1, it needs to know the exact width of the TextView . You can only do this by specifying a fixed size or by providing fixed sizes to other views. You do not want to do this.
You need to measure the width of the text in each TextView , as if it were being displayed . Once you know the width that each text will take, you can then make decisions in the code on how to get the layout to do what you want.
Add another View to LinearLayout with android:layout_weight="1000" . This will take up all unused space if the width of text1 and text2 does not exceed the width of the screen. Now calculate the width of text1 and the width of text2 as follows:
Rect bounds = new Rect(); Paint textPaint = textView1.getPaint(); textPaint.getTextBounds(text1, 0, text1.length(), bounds); int widthText1 = bounds.width(); textPaint = textView2.getPaint(); textPaint.getTextBounds(text2, 0, text2.length(), bounds); int widthText2 = bounds.width();
Now you know the width that text1 and text2 would need if they were fully displayed.
if (widthText1 + widthText2 > screenWidth) { View3.setVisibility(View.GONE);
In one case, View3 will take up all the remaining space. Otherwise, TextView1 should be ellipsed at the end.
I have not actually tested this, so don't be too heavy if this doesn't work.
source share