If you set a background color to the MultiTouchView views, then you will find that the color of the entire screen is same as the color of the 2nd view which was added.
I specified layout params for the child views and i was able to get the views to draw on screen. the modified code:
public class AndroidTouch extends Activity {
LinearLayout linear;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_c);
linear = (LinearLayout)findViewById(R.id.main);
Bitmap backgroundCard = BitmapFactory.decodeResource(getResources(), R.drawable.image1);
int w = backgroundCard.getWidth();
int h = backgroundCard.getHeight();
LayoutParams params = new LayoutParams(w, h);
MultiTouchView mt1 = new MultiTouchView(getApplicationContext(), backgroundCard);
//mt1.setBackgroundColor(Color.RED);//try uncommenting this wihtout layout params change
linear.addView(mt1, params);
Bitmap backgroundCard2 = BitmapFactory.decodeResource(getResources(), R.drawable.image2);
params = new LayoutParams(backgroundCard2.getWidth(), backgroundCard2.getHeight());
MultiTouchView mt2 = new MultiTouchView(getApplicationContext(), backgroundCard2);
//mt1.setBackgroundColor(Color.BLUE);<-- Entire screen turns blue
linear.addView(mt2, params);
}
}
But i believe you will face another problem after this. From the code it is evident that you are trying to draw the views at the touched positions. I would suggest using one single custom view and adding multiple images to the same view. Only in this case you have to determine which view needs to be drawn in a different co-ordinate and which view remains same.
Hope this helps