android - 如何在 Android 中使图像成为 Grid View 的背景?

标签 android gridview android-image

我正在为我的类(class)期末制作一个应用程序,它在 android 中使用 GridView。 我知道如何使用 Hex 使背景具有特定颜色,但我想知道是否可以使用 .png 等图像作为背景。

最佳答案

是的,就像任何其他 View 继承者一样,您可以将 XML 中的背景设置为可绘制资源:

<GridView ...
    android:background="@drawable/my_image"
    ...
/>

或者在代码中你可以设置后台资源:

GridView gridview = (GridView)findViewById(R.id.gridview);
gridview.setBackgroundResource(R.drawable.my_image);

关于android - 如何在 Android 中使图像成为 Grid View 的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5862555/

相关文章:

android - 如何在 Android 的 ListView 中显示图像列表?

android - 如何设置使用默认 Android 图像查看器查看位图的 Intent ?

android - 在 Android 上链接更新的库

php - 使用 Retrofit 在 Android 中使用 PHP 和 MySQL 开发的 RESTful API

android - 如何使用 Activity 页面而不是 Fragment 进行 Android 页面滑动?

android - 在运行 Playbook OS 2.0 的 Blackberry Playbook 上快速开发、调试和运行 android 应用程序的方法

css - 如何设置Gridview的列宽

Android 应用程序图标随运行时变化

c# - 在 asp.net gridview 中显示空格填充的记录

项目的android gridview行高最大值