나는 배경을 drawable
에서 설정 한 RelativeLayout
을 가지고 있습니다. RadioButton
을 선택하면 RelativeLayout
의 배경을 다른 배경으로 변경할 수있었습니다. 그런데 어떻게 변화가 생길 때 애니메이션을 줄까요?RelativeLayout 배경색
코드 : activity_main.xml : (당김)
<RelativeLayout
android:layout_width="80dp"
android:layout_height="50dp"
android:gravity="center"
android:background="@drawable/original"
android:id="@+id/rel1">
<RadioButton
android:id="@+id/radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
original.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#ffffff">
</solid>
<corners
android:radius="50dp">
</corners>
</shape>
pressed.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#2196F3">
</solid>
<corners
android:radius="50dp">
</corners>
</shape>
자바 클래스 :
radio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b){
relativeLayout.setBackgroundResource(R.drawable.pressed);
}
}
});
쉽게 ObjectAnimator를 사용하여 수행 할 수 있습니다. –
코드 – jobin
을 보내 주시겠습니까? https://stackoverflow.com/questions/11419141/fading-in-text-in-android-using-animationutils-loadanimation –