2011-11-16 14 views
2

我在android工作。Android:我如何繪製一個圖像的時間使用循環

我有這兩個圖像: - enter image description here

enter image description here

現在使用循環我想提請在運行時,這些圖像。所以請問我該怎麼做?

意味着它將在運行時決定這些圖像應該重複多少次。 終於我想畫這樣: - enter image description here

但這個比率可能會改變運行。請幫助我,我該如何做到這一點。你可以提供一些例子來實現這一點。 預先感謝您。

+0

我想要做同樣的事情,幫我PLZ – Rohit

回答

3

使用水平的LinearLayout。

for (int i=0; i < menCount; i++) { 

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

做女性形象也一樣..

+0

yashwanth先生,這是H11?意味着我應該在這裏採取什麼。一個圖像視圖或其他東西?像佈局一樣。 –

+0

hll是水平線性佈局。你在xml中聲明這個佈局,然後在代碼中獲得對它的引用,然後你開始向它添加圖像。 –

+0

謝謝你,yashwanth ...非常感謝你... –

4

根據您所提供的信息,它應該大致是這樣的:

// 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 
     } 
    } 
    /* ... */ 
} 
相關問題