首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Android :如何使用for循环多次绘制图像

Android :如何使用for循环多次绘制图像
EN

Stack Overflow用户
提问于 2011-11-16 17:54:13
回答 2查看 522关注 0票数 2

我在android上工作。

我有这两张图片:

现在使用for循环,我想在运行时绘制这些图像。请告诉我,我该怎么做呢?

意味着它将在运行时决定这些图像应该重复多少次。最后我想这样画:--

但这个比率可能会在运行时发生变化。请帮帮我,我该怎么做呢?你可以给我一些例子来实现这一点。提前谢谢你。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-16 18:03:40

使用水平LinearLayout。

代码语言:javascript
代码运行次数:0
运行
复制
for (int i=0; i < menCount; i++) {

      ImageView imageView = new ImageView(this);
      imageView.setImageDrawable(arg0);  //provide the drawable as argument.
      hll.addView(imageView);
}

对女性形象也是如此..

票数 3
EN

Stack Overflow用户

发布于 2011-11-16 17:59:25

根据你提供的信息,应该大致是这样的:

代码语言:javascript
代码运行次数:0
运行
复制
// 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
        }
    }
    /* ... */  
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8149656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档