FrontEnd/Android
android / 안드로이드 ] slotMechine Animation
언제나 변함없이
2019. 5. 29. 10:27
반응형
res에 animation 폴더를 생성한 후 anim resource file을 만들어 아래와 같이 만들어줍니다.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromYDelta="-5%p"
android:toYDelta="5%p"
android:duration="100"
android:repeatCount="10"/>
</set>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private Animation flowAnim;
private ImageView mSlotMechine;
private TextView mSlotText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
void init(){
mSlotMechine = (ImageView) findViewById(R.id.activity_main_slot);
mSlotText = (TextView)findViewById(R.id.activity_main_textview);
flowAnim = AnimationUtils.loadAnimation(this, R.anim.empty);
mSlotMechine.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSlotText.startAnimation(flowAnim);
}
});
}
}
슬롯머신을 클릭했을 때 startAnimation하도록 만든 간단한 slot machine 애니메이션입니다.
여기에 투명도도 바꾸고싶다면 아래와같은 식으로 작성하면 됩니다.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration = "6000"
android:repeatCount = "3"
/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1"
android:duration="6000"
android:repeatCount="3"
/>
</set>
반응형