아래에 게시 한 모든 코드는 원했던 것처럼 작동합니다. 참조 용으로 설정하고 비슷한 것을 얻으려는 사람이있을 수 있습니다. 그것은 간단하고 아주 잘 주석 처리되었습니다.Android 애니메이션 부작용 : 색상을 애니메이션 할 때 버튼의 모양이 바뀝니다.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="25dp"
/>
<solid
android:color="#0000FF"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="50dp"
android:height="50dp"
/>
</shape>
그리고 배열에 저장 버튼을 만드는 데 사용됩니다 (gameButtons
) : 그래서이
for(int i = 0; i < (numberOfButtons); i++)
{
//create a button:
Button oneBtn = new Button(this);
//get layout reference:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.game_window);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(btnSize, btnSize);
//get screen size:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
//randomize button's position:
Random r = new Random();
int randX = r.nextInt(height - btnSize);
int randY = r.nextInt(width - btnSize);
params.leftMargin = randY;
params.topMargin = randX;
//set button's parameteres:
oneBtn.setId(i);
oneBtn.setText(String.valueOf(i));
//make the button round, based on drawable/buttonshape.xml:
oneBtn.setBackgroundResource(R.drawable.buttonshape);
//add button to the view:
gameButtons[i] = oneBtn;
rl.addView(oneBtn, params);
}
그런 다음이 단추에 애니메이션을 적용하려고합니다. 애니메이션은 색 몇 번 (파란색 -> 노란색 -> 블루 -> ...) 이 애니메이션뿐만 아니라 (내가 원하는 않습니다)
private void changeButtonColor(final Button button){
int animationTime = 800;
//set colors rgb->int
int blueInt = Color.rgb(0,0,255);
int yellowInt = Color.rgb(255,255,0);
//craete an animation:
ValueAnimator anim = new ValueAnimator();
anim.setIntValues(blueInt, yellowInt, blueInt);
anim.setEvaluator(new ArgbEvaluator());
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//animate button's color:
button.setBackgroundColor((Integer)valueAnimator.getAnimatedValue());
}
});
//final settings to animation an start:
anim.setInterpolator(new LinearInterpolator());
anim.setDuration(animationTime);
anim.start();
}
그리고 버튼이 깜박 잘 작동을 변경하여 깜박이는 버튼을 만든다 사실, 내가 호출 할 때 changeButtonColor()
버튼이 모양이 사각형으로 바뀌는 것을 제외하고 싶었던 것처럼.
위 애니메이션이 setBackgroundResource()
보다 우선 적용되는 것으로 보이지만, 애니메이션 내에서 setBackgroundResource()
을 넣어 여러 방법으로 방지하려고 시도했지만 결과가 없습니다.
이 부작용을 제거하는 방법은 어떤 것이 있습니까?