java - 如何使 textview drawableright 始终与字符串的最后一个字符对齐
问题描述
我正在开发一个项目,该项目需要一个 textview 视图,其右侧有一个可绘制对象,或者 textview 右侧有一个 imageview 视图。问题陈述是图像应该始终与中心的文本对齐。如果文本是单行,那么一切看起来都很好,但是当文本是多行文本时,图像将保持在两行的中心。我尝试了多种方法,包括丰富的drawables和verticleimage span,但都没有帮助。在图像中,第一个和第二个是我到目前为止所得到的,但第三个是它应该是预期的结果(即使第一个是正确的,如果它是单行文本)。在此处输入图像描述
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/media_item_poster_width"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/browse_media_button"
android:background="@drawable/poster_overlay_selector"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/media_browser_item_padding">
<TextView
android:id="@+id/view_all_number_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/media_poster"
android:layout_marginStart="@dimen/media_item_poster"
android:layout_marginBottom="@dimen/media_item_poster"
android:ellipsize="end"
android:maxWidth="@dimen/browse_view_all_number_tv_max_width"
android:maxLines="2"
android:textColor="@color/anz_text_color_primary"
android:textSize="@dimen/media_item_poster_view_all"
app:mainResourcePkgName="@string/resource_pkg_name_global"
tools:text="48 Titles" />
<ImageView
android:id="@+id/view_all_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_view_all_arrow"
android:layout_alignBottom="@+id/media_poster"
android:layout_marginBottom="@dimen/media_item_poster_view_all"
android:layout_toEndOf="@+id/view_all_number_tv"
android:layout_marginStart="@dimen/view_all_arrow_margin_start"
android:layout_marginEnd="@dimen/media_item_poster_view"
app:mainResourcePkgName="@string/resource_pkg_name_module"
app:labelsResourcePkgName="@string/resource_pkg_name_global" />
</RelativeLayout>
解决方案
推荐阅读
- javascript - 通过实例方法和 this 访问 JS 类/对象变量 - 执行上下文
- laravel - 如何在 Laravel 中使用 filepond 发送 DELETE 请求?
- c# - 由于 DLL 引用中的保护级别,类不可访问
- javascript - 我可以从一开始就隐藏一张桌子吗?
- sql - Oracle SQL - select column of explicitly defined values
- android - 编辑 json 文本 http3
- javascript - 上传带有其他信息的图像文件(文本)
- c# - Razor - Weird issue with updating class attribute in a foreach loop
- reactjs - How do I uglify code when building Gatsby sites?
- vue.js - Store references to elements that are used frequently