안드로이드 개발 질문/답변
(글 수 45,052)
다음과 같이 FrameLayout을 상속받는 myLayout을 만들고,
화면에 터치시 터치 영역에 Circle을 만들기 위해 ImageView를 상속받는 myCircle클래스를 생성하였습니다.
MyCircle 클래스 내부에서는 Alpha Animation과 Scale Animation을 생성하여, AnimationSet 클래스에 Add한뒤에
AnimationSet 를 시작하였습니다. 이때,, 오직 알파 애니메이션만 먹질 않네요 ㅜㅜ
ㅇㅇㅇ
public class mylayout extends FrameLayout implements View.OnClickListener {......
public mylayout(Context context){
super(context);
init(context);
}
void init(Context context){
this.setLayoutParams(new
LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
mButton = new Button(getContext());
mButton.setText("Delete all Created Circle.");
mButton.setId(10);
mButton.setOnClickListener(this);
bitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.change_sea01);
this.addView(mButton,new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_DOWN) {
this.addView(new MyCircleView(getContext(), (int)event.getX(),
(int)event.getY()));
return true;
} else if(event.getAction() == MotionEvent.ACTION_MOVE) {
this.addView(new MyCircleView(getContext(),(int)event.getX(),
(int)event.getY()));
return true;
}
return super.onTouchEvent(event);
}다음은 위의 mylayout 클래스에 has a 관계로 포함되는 myCircle 클래스입니다.
aaaaaaa
class MyCircleView extends ImageView{ .............
public MyCircleView(Context context, int xPos, int yPos) {
super(context);
pnt = new Paint();
pnt.setAntiAlias(true);
bDelete = false;
bmpCircle = BitmapFactory.decodeResource(context.getResources(),
R.drawable.img_click);
this.xPos = xPos;
this.yPos = yPos;
xWidth = bmpCircle.getWidth()/2;
yWidht = bmpCircle.getHeight()/2;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(setAnimation == null){
createAnimation(canvas);
}
canvas.drawBitmap(bmpCircle, xPos - xWidth, yPos - yWidht, pnt);
}
public void createAnimation(final Canvas canvas) {
AlphaAnimation alpha;
ScaleAnimation scale;
alpha = new AlphaAnimation(1.0f, 0.0f);
scale = new ScaleAnimation(1, 2, 1, 2, Animation.ABSOLUTE, xPos- xWidth,
Animation.ABSOLUTE, yPos - yWidht);
setAnimation = new AnimationSet(false);
setAnimation.addAnimation(alpha);
setAnimation.addAnimation(scale);
setAnimation.setDuration(3000);
startAnimation(setAnimation);
}
}



setAnimation.addAnimation(alpha);
setAnimation.addAnimation(scale);
이렇게 두개 주신거 같은데요 아마 이렇게 주시면서 하나에만 먹어 버린거 같아요.
정확히는 뒤의 애니메이션만 적용이 되는거죠
두개의 애니메이션을 주고 싶으신가 본데요
저는 이런식으로 줬습니다.
ani = AnimationUtils.loadAnimation(this, R.anim.scalealpharotate);
img_uresii.startAnimation(ani);
<?xml version="1.0" encoding="UTF-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<scale
android:fromXScale="0.2"
android:toXScale="1.8"
android:fromYScale="0.2"
android:toYScale="1.8"
android:pivotX="50%"
android:pivotY="50%"
android:duration="900" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="900" />
<rotate
android:fromDegrees="0"
android:toDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:duration="900" />
</set>
제가 여기 글쓰는게 익숙치 않아서 잘 모르시면 리플 주세요