自定义圆和属性动画

自定义画圆


public class Custom extends View {
    public Custom(Context context) {
        super(context);
    }

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

    public Custom(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        canvas.drawCircle(50,50,50,paint);
    }
}

activity布局

	//自定义圆的控件
  <crq.bwei.com.qiu.Custom
        android:id="@+id/custom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        />

activity代码

public class MainActivity extends AppCompatActivity {

    private Custom custom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        custom = findViewById(R.id.custom);
        custom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                PropertyValuesHolder alpha1 = PropertyValuesHolder.ofFloat("alpha", 1f, 0f, 1f);
                PropertyValuesHolder scaleX1 = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
                PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
                PropertyValuesHolder rotation1 = PropertyValuesHolder.ofFloat("rotation", 0.0f, 360f);
                PropertyValuesHolder translationX1 = PropertyValuesHolder.ofFloat("translationX",200f);
                PropertyValuesHolder translationY1 = PropertyValuesHolder.ofFloat("translationY",200f);
                PropertyValuesHolder translationX2 = PropertyValuesHolder.ofFloat("translationX",0f);
                PropertyValuesHolder translationY2 = PropertyValuesHolder.ofFloat("translationY",0f);

                //****************
          /*      PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f,0f, 1f);
                PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f,	0, 1f);
                PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f,	0, 1f);*/

                ObjectAnimator.ofPropertyValuesHolder(custom, translationY1).setDuration(3000).start();

            }
        });

        //3秒后跳转
        Timer timer=new Timer();
        TimerTask task=new TimerTask() {
            @Override
            public void run() {
                Intent intent=new Intent(MainActivity.this,TwoActivity.class);
                startActivity(intent);
            }
        };
        timer.schedule(task,3000);


    }
}

'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值