2014-09-28 45 views
-1

我有一個遊戲,每個級別都有一個回收流程,但是到時候會更困難, 我可以製作普通功能的視圖並將其擴展到每個級別活動??製作自定義視圖並將其從其他活動中延伸

任何一個有解決方案?或另一個想法? (我需要每個級別的分離活動)

這是我做了什麼......

public class Prev extends Activity{ 
private Bitmap image1; 
private Bitmap image2; 
private Bitmap image3; 
private Bitmap image4; 

private final int IMAGE_1_X = 50; 
private final int IMAGE_2_X = 450; 
private final int IMAGE_3_X = 50; 
private final int IMAGE_4_X = 450; 

private final int IMAGE_1_Y = 50; 
private final int IMAGE_2_Y = 50; 
private final int IMAGE_3_Y = 300; 
private final int IMAGE_4_Y = 300; 


@Override 
    protected void onCreate(Bundle savedInstanceState) 
{ 
     super.onCreate(savedInstanceState); 
     Preview p = new Preview(this); 
     setContentView(p); 
} 
public void setImages(Bitmap image1, Bitmap image2, Bitmap image3, Bitmap image4) 
{ 
    this.image1 = image1; 
    this.image2 = image2; 
    this.image3 = image3; 
    this.image4 = image4; 
} 
public void setRawsNames(String sound_1, String sound_2, String sound_3, String sound_4) 
{ 
    this.sound_1 = sound_1; 
    this.sound_2 = sound_2; 
    this.sound_3 = sound_3; 
    this.sound_4 = sound_4; 
} 
public class Preview extends SurfaceView{ 

public Preview(Context context) 
{ 
    super(context); 
} 
@Override 
public void onDraw(Canvas canvas) 
{ 
    canvas.drawBitmap(image1, IMAGE_1_X, IMAGE_1_Y,null); 
    canvas.drawBitmap(image2, IMAGE_2_X, IMAGE_2_Y,null); 
    canvas.drawBitmap(image3, IMAGE_3_X, IMAGE_3_Y,null); 
    canvas.drawBitmap(image4, IMAGE_4_X, IMAGE_4_Y,null); 
} 
} 

}

在這裏,我將擴展上流

public class MainActivity extends Prev { 
private Bitmap image1; 
private Bitmap image2; 
private Bitmap image3; 
private Bitmap image4; 

public MainActivity() 
{ 
    preperImages(); 
    setImages(image1, image2, image3, image4); 
} 
private void preperImages() 
{ 
    image1 = BitmapFactory.decodeResource(getResources(), R.drawable.one); 
    image2 = BitmapFactory.decodeResource(getResources(), R.drawable.two); 
    image3 = BitmapFactory.decodeResource(getResources(), R.drawable.three); 
    image4 = BitmapFactory.decodeResource(getResources(), R.drawable.four); 

} 

}

回答

0

不確定你到底想要達到什麼目的。據我所知,你想重用一個視圖。爲此,您可以在佈局中使用include標記。

相關問題