EricLog
Published in

EricLog

文字末端 icon 排版

以前試過做一些 UI 是 TextView 旁邊有一個 icon,然後同一行最右邊會有另一個 Button。如果文字過長就加上省略號,但文字不夠長的話 icon 要緊貼那個文字而那個 Button 就固定在右邊。 TextView 有 compound drawable,但如果想那個 icon 有 click listener 又用不了。所以最後都要分開 TextViewImageView/ ImageButton 兩個 view。

失敗例子:ConstraintLayout horizontal chain

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_light">

<TextView
android:id="@+id/title0"
android:layout_width="wrap_content"

--

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Eric Li

Eric Li

Hongkonger + Android developer

More from Medium

The Story of FPS Meter

Say Hello to SQLDelight

First Impression of Jetpack Compose, QoL Issues

Know more about Network Service Discovery(NSD) in Android and approaches to discover services in…