Reputation: 37
When a single line of text is too long, how can I make TextView always display the last part of it?
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/display_sum"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="0.00"
android:text=""
android:textSize="50sp"
android:textStyle="bold"
android:layout_gravity="right"
android:gravity="right"/>
</HorizontalScrollView>
I want this:
not this:
Upvotes: 1
Views: 847
Reputation: 40
I think so the below code may help to you.
HorizontalScrollView horizontalScrollView = (HorizontalScrollView) findViewById(R.id.YourIdName)
horizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_FORWARD);
//Observe for a layout change
ViewTreeObserver viewTreeObserver = horizontalScrollView .getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
horizontalScrollView .fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
});
}
}
Upvotes: 3
Reputation: 1561
In that case you have to set
android:ellipsize="start"
android:singleLine="true"
your textview should like
<TextView
android:id="@+id/textView"
android:ellipsize="start"
android:singleLine="true"
android:text="very big text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Upvotes: 1