Android - TextView添加图片

时间:2025-02-09 09:14:20

TextView添加图片


本文地址:/caroline_wendy


Android UI设计时,经常需要在文字周围添加图片

比较简单的方法是直接使用Layout把View组合到一起:

<ImageView
     android:layout_width=“wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/icon_home_askdoc"
     android:scaleType="fitXY"
     android:layout_above="@+id/asking_doctor"
     android:layout_centerHorizontal="true"/>
ImageView,适配图片大小,填充"scaleType:fitXY",视图的水平居中"centerHorizontal:true"。

也可以直接在TextView的周围添加图片(drawable):
<TextView
     style="@style/HomepageGridMenuTextStyle"
     android:drawablePadding="8dp"
     android:drawableTop="@drawable/icon_home_avatar"
     android:text="@string/home_avatar"/>
TextView, drawableTop 在文字上面添加图片,但是 无法调节图片的属性