2
私は2つのカスタムビューを維持しようとしていますが、私はフェードインフェードアウトを保ちましたが、両方のカスタムビューを見ることができません。しかし私は一度に両方のビューを見ることができないので、私は間違っていた場所を教えてください。2つのレイアウトで2つ以上のビューを表示することはできますか?
MyView myview;
MyView1 myview1;
RelativeLayout relativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myview=new MyView(this);
myview.setBackgroundColor(color.white);
setContentView(myview);
myview = new MyView(this);
myview.setBackgroundColor(Color.WHITE);
myview1=new MyView1(this);
myview1.setBackgroundColor(color.white);
setContentView(myview1);
myview1 = new MyView1(this);
myview1.setBackgroundColor(Color.WHITE);
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.setId(0);
relativeLayout.setBackgroundColor(Color.WHITE);
myview = new MyView(this);
myview.setId(004);
RelativeLayout.LayoutParams lp6 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
myview.setLayoutParams(lp6);
relativeLayout.addView(myview,lp6);
myview1 = new MyView1(this);
myview1.setId(8);
RelativeLayout.LayoutParams lp008 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
myview1.setLayoutParams(lp008);
relativeLayout.addView(myview1,lp008);
Button button1 = new Button(this);
RelativeLayout.LayoutParams lp1=new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
button1.setText("click");
relativeLayout.addView(button1,lp1);
button1.setOnClickListener(this);
setContentView(relativeLayout);
}
public class MyView extends View {
public MyView(Context c) {
super(c);
}
protected void onDraw(Canvas canvas) {
Bitmap _scratch = BitmapFactory.decodeResource(getResources(),R.drawable.apple);
canvas.drawBitmap(_scratch, 840, 450, null);
}
}
public class MyView1 extends View{
public MyView1(Context context) {
super(context);
}
protected void onDraw(Canvas canvas) {
Bitmap scratch=BitmapFactory.decodeResource(getResources(), R.drawable.ant);
canvas.drawBitmap(scratch, 840, 450, null);
}
}
public void onClick(View v) {
if(myview1.getVisibility() == View.VISIBLE) {
Animation out = AnimationUtils.makeOutAnimation(this, true);
myview1.startAnimation(out);
myview1.setVisibility(View.INVISIBLE);
} else {
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
myview1.startAnimation(in);
myview1.setVisibility(View.VISIBLE);
}
}
}