开发者

Displaying both text and icons in gridview

I want to disp开发者_如何学Pythonlay the icons in grid view and also text heading for that icon just below it. can some one help me out.


You are supplying an Adapter to the GridView. Have that Adapter return Views for the cells that have icons "and also text heading for that icon just below it". You might use a vertical LinearLayout with an ImageView and TextView children, for example.

Here is a free excerpt from one of my books that shows how to do this sort of thing for a ListView -- the same technique holds for GridView.


If you are beggining in Android like me, I found out that the simplest thing to start with is to:

1) Set each grid to contain a textview

2) Set background (icons in your case) to each textview; plus add the text.

Like:

//textview is a the textview in the cells
textview.setBackgroundResource(<your icon resource>);

The text is added and modified normally:

textview.setTextColor(Color.BLACK);
textview.setTextAppearance(mContext, R.<style xml>);
textview.setGravity(Gravity.BOTTOM);

You'd most likely need to properly set the text position and color so you have a readable result. Then you may also set the background properties (you can check textview methods)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜