Android - 如何显示TextView的最后一部分
Android - How to display the last part of TextView
当单行文本太长时,如何让TextView一直显示最后一部分?
<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>
我想要这个:
不是这个:
在那种情况下你必须设置
android:ellipsize="start"
android:singleLine="true"
你的 textview 应该会喜欢
<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" />
我想下面的代码可能对你有帮助。
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);
}
});
}
}
当单行文本太长时,如何让TextView一直显示最后一部分?
<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>
我想要这个:
不是这个:
在那种情况下你必须设置
android:ellipsize="start"
android:singleLine="true"
你的 textview 应该会喜欢
<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" />
我想下面的代码可能对你有帮助。
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);
}
});
}
}