属性动画

平移 旋转 渐变 缩放
首先是布局


    <gxq.com.day09.MyView
        android:id="@+id/kaoimage"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#aaaddd" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/aa">

        <Button
            android:id="@+id/py"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="平移" />

        <Button
            android:id="@+id/jb"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="渐变" />

        <Button
            android:id="@+id/xz"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="旋转" />

        <Button
            android:id="@+id/sf"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="缩放" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/aa"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <Button
            android:id="@+id/vvvvv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="ValueAnimator" />

        <Button
            android:id="@+id/set"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="ObjectAnimator" />

    </LinearLayout>

主页的点击事件

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);


    }

    @OnClick({R.id.py, R.id.jb, R.id.xz, R.id.sf, R.id.vvvvv, R.id.set})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.py:
                AnimatorSet set1 = new AnimatorSet();
                ObjectAnimator translationX = ObjectAnimator.ofFloat(kaoimage, "translationX", 0, 600);
                ObjectAnimator translationY = ObjectAnimator.ofFloat(kaoimage, "translationY", 0, 900);
                //translationX.start();
                set1.play(translationX).with(translationY);
                set1.setDuration(3000);
                set1.start();
                break;
            case R.id.jb:
                ObjectAnimator alpha = ObjectAnimator.ofFloat(kaoimage, "alpha", 1, 0,1);
                alpha.setDuration(3000);
                alpha.start();
                break;
            case R.id.xz:
                ObjectAnimator rotation = ObjectAnimator.ofFloat(kaoimage, "rotation", 360, 0);
                rotation.setDuration(3000);
                rotation.start();
                break;
            case R.id.sf:
                AnimatorSet set2 = new AnimatorSet();
                ObjectAnimator scaleX = ObjectAnimator.ofFloat(kaoimage, "scaleX", 1, 3,1);
                ObjectAnimator scaleY = ObjectAnimator.ofFloat(kaoimage, "scaleY", 1,3, 1);
                set2.play(scaleX).with(scaleY);
                set2.setDuration(3000);
                set2.start();
                break;
            case R.id.vvvvv:
                break;
            case R.id.set:
                break;
        }
    }

自定义动画

public class MyView extends android.support.v7.widget.AppCompatImageView {

    private int i;

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int width = getMeasuredWidth();
        int height = getMeasuredHeight();
        //半径
        i = Math.min(width, height) / 2;

    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //画笔
        Paint paint = new Paint();
        //绘制
        canvas.drawCircle(i,i,i,paint);
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值