我有一个RadioButton
设置为drawableTop
的{{1}}。 LayerList
看起来像这样
LayerList
在<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/image_radio_button_bg_selector" />
<size
android:width="@dimen/imageRadioButtonDrawableSize"
android:height="@dimen/imageRadioButtonDrawableSize" />
<corners android:radius="@dimen/imageRadioButtonDrawableRadius" />
</shape>
</item>
<layer-list>
被选中或未选中的情况下,我希望能够对该可绘制对象进行动画处理。选中RadioButton时,Drawable需要从50%缩放到100%,反之亦然。有没有一种方法可以在复合drawable中添加动画?特别是当drawable由RadioButton
驱动而不是Color Selector
驱动时。 (在我的情况下为Drawable Selector
那个颜色选择器看起来像这样
image_radio_button_bg_selector
答案 0 :(得分:0)
在res / anim / scale.xml中创建文件
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:pivotX="50%" // anchor point in x-axis->
android:pivotY="50%" // anchor point in x-axis
android:fromYScale="0.5" // from size Y axis
android:fromXScale="0.5" // from size X axis
android:interpolator="@android:anim/bounce_interpolator"
android:toYScale="1.0" // to size Y axis
android:toXScale="1.0" // to size X axis
android:duration="250"/> // time of duration in milliseconds
</set>
活动文件中的用法
RadioGroup rGroup = (RadioGroup)findViewById(R.id.radioGroup);
RadioButton checkedRadioButton =(RadioButton)rGroup.findViewById(rGroup.getCheckedRadioButtonId());
rGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton checkedRadioButton = (RadioButton)group.findViewById(checkedId);
Animation bulge = AnimationUtils.loadAnimation(getApplication(), R.anim.scale);
checkedRadioButton.startAnimation(bulge);
}
});