How to make an image the background of Grid View in Android?
I am making an app for my class final that uses a GridView in android. I know how to make the background a certain color using Hex, but I wanted to know if it开发者_开发知识库 is possible to use an image like a .png as the background instead.
Yes, just like any other View
inheritor you can set the background in XML to be a drawable resource:
<GridView ...
android:background="@drawable/my_image"
...
/>
or in code you can set the background resource:
GridView gridview = (GridView)findViewById(R.id.gridview);
gridview.setBackgroundResource(R.drawable.my_image);
Try gridView.setBackgroundDrawable(R.drawable.<pictureid>);
.
精彩评论