【发布时间】:2018-10-03 12:57:52
【问题描述】:
我有一个布局(可以是相对的、线性的或约束的)
TextView 与父级左侧对齐,然后 ImageView(固定宽度)从右侧开始对齐到 textView。
我希望先渲染图像,然后再渲染文本视图。
意思是我希望文本视图在图像渲染后根据左边的空间被截断。
<RelativeLayout
android:id="@+id/account_name_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="@dimen/account_menu_account_name_layout_bottom_margin">
<TextView
android:id="@+id/account_name"
style="@style/AccountDataAccountName"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:lines="1"
android:ellipsize="end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
tools:text="emailisverylongaswellwewantittogettruncated@gmail.longdomain.com"/>
<ImageView
android:id="@+id/account_name_chevron"
android:layout_width="@dimen/account_menu_chevron_size"
android:minWidth="@dimen/account_menu_chevron_size"
android:layout_height="@dimen/account_menu_chevron_size"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/account_name"
android:layout_marginTop="@dimen/account_menu_chevron_top_margin"
android:layout_marginLeft="@dimen/account_menu_chevron_left_margin"/>
</RelativeLayout>
我尝试了几个选项:
1) 告诉文本要留在图像视图中
2) 将权重放在文本视图上 - 在两个元素之间制造间隙。
3) 将 minWidth 设置为图像视图 - 只是使 imageView 比例变小并没有帮助。
知道如何先渲染图像以及如何根据左侧宽度限制 textView 的宽度吗?
【问题讨论】:
标签: android android-layout textview truncate android-relativelayout