Android的 - 只有在父视图播放动画 [英] Android - Playing animation only on parent view

查看:160
本文介绍了Android的 - 只有在父视图播放动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让动画运行只在父视图,让孩子们观看完整(即没有它们动画)?

How can I make an animation run only on the parent view, leaving the children views intact (ie, without animating them)?

下面是我的尝试:

public class TurnButton extends RelativeLayout implements OnClickListener, AnimationListener{

    private static final String TAG = TurnButton.class.getSimpleName();

    private final int textViewID = 1;

    public TurnButton(final Context context, final AttributeSet attrs, final int defStyle) {

        super(context, attrs, defStyle);
        setEverything();
    }

    public TurnButton(final Context context, final AttributeSet attrs) {

        super(context, attrs);
        setEverything();
    }

    public TurnButton(final Context context) {

        super(context);
        setEverything();
    }

    private void setEverything(){

        setOnClickListener(this);

        final TextView textViewNumber = new TextView(ThisApplication.getContext());
        textViewNumber.setId(textViewID);
        textViewNumber.setText("30");
        textViewNumber.setTextColor( ThisApplication.getContext().getResources().getColor(R.color.white) );

        final RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        relativeParams.addRule(RelativeLayout.CENTER_IN_PARENT);

        addView(textViewNumber, relativeParams);
    }

    @Override
    public void onClick(final View view) {

        final RotateAnimation rotate = new RotateAnimation( view.getRotation(), view.getRotation() - 360.0f, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
                                                            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(300);
        rotate.setFillEnabled(true);
        rotate.setFillAfter(true);
        view.startAnimation(rotate);

        view.findViewById(textViewID).setRotation(0);
    }
}

我想旋转TurnButton视图不旋转的TextView 我加在它的中心。

推荐答案

这是通过应用反转到子视图(TextView中):

It is possible by applying reverse rotation to child view (TextView):

@Override
public void onClick(final View view) {

    final RotateAnimation rotate = new RotateAnimation(view.getRotation(),
            view.getRotation() - 360.0f, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    rotate.setDuration(300);
    rotate.setFillEnabled(true);
    rotate.setFillAfter(true);
    view.startAnimation(rotate);

    final TextView textView = (TextView)view.findViewById(textViewID);
    final RotateAnimation reverseRotate = new RotateAnimation(view.getRotation(),
            360.0f - view.getRotation(), RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    reverseRotate.setDuration(300);
    reverseRotate.setFillEnabled(true);
    reverseRotate.setFillAfter(true);
    textView.startAnimation(reverseRotate);
}

这篇关于Android的 - 只有在父视图播放动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆