【发布时间】:2012-12-11 17:04:08
【问题描述】:
设置背景似乎没有给出任何关于 android 大小的提示。
因此,我正在寻找一种方法来创建具有特定颜色的图像。
(如果能用xml就更好了)
在 iOS 中,这可以通过
来实现+ (UIImage*)placeHolderImage
{
static UIImage* image = nil;
if(image != nil)
return image;
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
// Seashell color
UIColor* color = [UIColor colorWithRed:255/255.0 green:245/255.0 blue:238/255.0 alpha:1.0];
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
【问题讨论】:
-
我对你想要完成的事情有点困惑。颜色与大小有什么关系?您是否尝试过在 axml 布局文件中使用 Image 并明确指定宽度和高度?
-
我有一个包含图像的列表视图。当我不设置 src 时,图像视图首先具有宽度 0(因此使行折叠),当设置图像时,它的高度会改变..