我在android上工作。
我有这两张图片:
和
现在使用for循环,我想在运行时绘制这些图像。请告诉我,我该怎么做呢?
意味着它将在运行时决定这些图像应该重复多少次。最后我想这样画:--
但这个比率可能会在运行时发生变化。请帮帮我,我该怎么做呢?你可以给我一些例子来实现这一点。提前谢谢你。
发布于 2011-11-16 10:03:40
使用水平LinearLayout。
for (int i=0; i < menCount; i++) {
ImageView imageView = new ImageView(this);
imageView.setImageDrawable(arg0); //provide the drawable as argument.
hll.addView(imageView);
}
对女性形象也是如此..
发布于 2011-11-16 09:59:25
根据你提供的信息,应该大致是这样的:
// A is the class you want to paint images. It should be subclass of View class
class A extends View {
/* Other code... */
// You need to overwrite onDraw, this is where drawing to screen is made
public void onDraw(Canvas c) {
// x is an array containing the coordinates
ArrayList<Point> coordinates coors;
// You need to calculate coordinates in runtime and set them
x = ...
for(int i = 0; i < coors.size(); i++) {
c.drawBitmap(bitmap, coors.get(i).x, coors.get(i).y, null); // Tells system to paint image to coordinates x,y
}
}
/* ... */
}
https://stackoverflow.com/questions/8149656
复制