如何在ImageView上添加文字

作者:分开不是尽头 | 创建时间: 2023-07-18
ImageView中是不能写文字的,文字覆盖图片的这个需求的话 你可以考虑使用帧布局。...
如何在ImageView上添加文字

操作方法

第一种方法: 运行结果是字符串覆盖在图片上 [code]<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     >     <ImageView           android:layout_width="wrap_content"            android:layout_height="wrap_content"           android:src="@drawable/image"       />       <TextView           android:layout_width="wrap_content"            android:layout_height="wrap_content"           android:text="MOMO"           android:background="#FF0000"           android:textColor="#000000"             android:textSize="18dip"         />   </FrameLayout>[/code]

第二种方法: 利用框架构造吧,这样可以再代码里实现 <FrameLayout android:id="@+id/liadjacentleft_mid" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/image_music" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/back_music" android:scaleType="matrix" /> <TextView android:id="@+id/txt_music" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#FF0000" android:textColor="#000000" android:textSize="18dip" />                         </FrameLayout>

点击展开全文

更多推荐