Android:如何将背景图像添加到GridLayout? [英] Android: How I can I add a background image to a GridLayout?

查看:68
本文介绍了Android:如何将背景图像添加到GridLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满按钮的GridLayout-类似于按钮之间有空格的计算.我想给背景蒙皮,包括按钮之间的那些区域,而不是按钮本身.

I have a GridLayout full of buttons - similar to a calculate with spaces between the buttons. I wants to skin the background including the those areas between the buttons but not the buttons themselves.

做到这一点的最佳方法是什么?是否可以在GridLayout本身上设置背景图像,还是需要创建View层次结构?

What is the best way to do this? Is there a means of setting a background image on the GridLayout itself or do I need to create a View hierarchy?

我已经开始尝试将子视图添加到父视图中,但是似乎只能将视图添加到ViewGroup派生类中?

I had started experimenting thinking that child Views can be added to parent Views but it would appear that you can only add Views to ViewGroup derived classes?

在没有背景的情况下,我正在动态构建GridLayout,并使用setContentView(gridLayout)将其添加到活动的默认布局中.

Without a background, I'm dynamically constructing my GridLayout and adding it to the activity's default layout using setContentView( gridLayout ).

请问我该怎么做?

我真正想了解的是如何组成复杂的视图层次结构.看来,gridLayout.setBackground()的简单方法也需要API 16,并且我也在我的设备上使用API​​ 14.

What I would really like to understand is how to compose complex view hierachies. It also appears the simple approach of gridLayout.setBackground() requires API 16 and I'm using API 14 for my devices too.

推荐答案

GridView源自 void setBackgroundResource()的方法,您可以在网格视图对象上调用它,并将可绘制资源的ID传递给它.此方法是从API级别1开始引入的,因此您不必担心API兼容性问题.

GridView is derived from View class. The View class has a method called void setBackgroundResource (), you can call it on your grid view object, pass an id of a drawable resource to it. This method was introduced since API level 1, so you don't have to worry about API compatibility issues.

这篇关于Android:如何将背景图像添加到GridLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆