开发者

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>);.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜