怎么样在gridview中动态添加图片和文字

怎么样在gridview中动态添加图片和文字,第1张

ImageView中是不能写文字的,单单的只是向实现文字覆盖图片,可以使用帧布局,运行结果是字符串覆盖在图片上.

代码:

<?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>

你可以用ArrayList当数据源,每次加一张图片都放到ArrayList里面去,再通过你GridView的设配器通知更新:imgAdapter.notifyDataSetChanged()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11601494.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存