android - Android - 如何显示 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>
我要这个:
不是这个:
解决方案
我认为下面的代码可能对您有所帮助。
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);
}
});
}
}
推荐阅读
- python - Python 无法下载带有无扩展名的动态 URL 的 excel 文件
- android - 如何使用 Jetpack Compose 使 LinearProgressIndicator 宽度动态化
- javascript - React.js 中的 Axios 网络错误 createError.js:16
- javascript - 如何在不和谐中找到消息的作者,以及如何使用它来确定它是否具有命令的正确权限
- javascript - VictoryChart 不更改日期数据
- ios - 修复 iOS 15 UINavigationBar
- android - Kotlin - 事件前的 WorkManager 通知
- html - TailwindCSS - 将所有网格项目设置为相同的高度
- javascript - 尝试使用 axios post 请求上传文件
- java - Hibernate / Spring Data JPA 在尝试使用嵌套对象持久化父对象时偶尔会失败