Android实现选中变大变小效果

作者: 懵懵懂懂_YOYO | 来源:发表于2022-07-13 16:11 被阅读0次

1.变大

    AnimationSet animationSet = new AnimationSet(true);
        ScaleAnimation animation = new ScaleAnimation(1.0f, 1.1f, 1.0f, 1.1f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(500);
        animation.setFillAfter(true);
        animationSet.addAnimation(animation);
        animationSet.setFillAfter(true);
        view.clearAnimation();
        view.startAnimation(animationSet);

2.变小

    AnimationSet animationSet = new AnimationSet(true);
        ScaleAnimation animation = new ScaleAnimation(1.1f, 1.0f, 1.1f, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(500);
        animation.setFillAfter(true);
        animationSet.addAnimation(animation);
        animationSet.setFillAfter(true);
        view.startAnimation(animationSet);

3.参数解释:

AnimationSet使用的默认构造器参数为boolean型,设置为true可以使用。

ScaleAnimation为缩放的动画类,参数很多,依次是:fromX(起始X的位置),toX(结束X的位置),fromY(起始Y的位置),toY(结束Y的位置),pivotXType( X选择的中心点,就是X旋转所不改变的依赖点,有三种参数,这里我们使用:RELATIVE_TO_SELF,意思是当前设定的View的浮点数和控件的长、宽的乘积),pivotXValue(这里就是当前设置的view的浮点数的大小),pivotYType(同X),pivotYValue(同X)。这里0.5f指代的是控件的中心位置。

4.设置自定义的OnFouseChangeListener监听事件:

class HomeFocusListener implements View.OnFocusChangeListener {
 
        @Override
        public void onFocusChange(View view, boolean b) {
            if (b) {
                ...(放大)
            } else {
                ...(缩小)
            }
        }
    }

相关文章

网友评论

    本文标题:Android实现选中变大变小效果

    本文链接:https://www.haomeiwen.com/subject/mpktirtx.html