前言
最近开发需求,就是名称后面加一个查看按钮。显示条件是文字只允许一行,超出部分显示省略号,并且右边紧挨着一个图标。点击条件是只有图标可以点击。先看效果图。
一、效果图
效果1:
效果2:
二、踩坑
因为想着条件是图标要单独点击,第一想到的就是使用ImageView实现。
踩坑1:
一开始,采用的方案是TextView+ImageView的方式,如下:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_resume_details_list_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
tools:text="xxxxxxxxxxx" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="xxx"
/>
</LinearLayout>
效果:文字超出一行时却是出现省略号,但就会把图标挤出屏幕外。
结果: 看不见图标了。 失败!
踩坑2:
我使用 weight 权重方式,这样就能保证文字超出一行时,能让图标留在屏幕内。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">