参考如下
用LayoutParams:
RelativeLayout insertLayout = (RelativeLayout)view1.findViewById(R.id.screen);//screen是一个RelativeLayout 布局的id
ImageView imgApple2 = new ImageView(MainActivity.this);
imgApple2.setBackgroundColor(Color.parseColor("#ffb6b4"));
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(100, 100);
layoutParams.topMargin=8;
layoutParams.leftMargin=8;
layoutParams.rightMargin=8;
layoutParams.bottomMargin=8;
insertLayout.addView(imgApple2,layoutParams);
建议多用动画效果,做游戏更要利用起来了,掉血的时候textview显示settext掉血量.之后设置一个动画,里面包括两种动画效果,一个是TransAnimation让textview由下往上走,一个是透明过渡效果AlphaAnimation(大概是这个名,记不清了)使透明度由100-0...