floatingActionButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = ev.getX();
downY = ev.getY();
isClick = true;
break;
case MotionEvent.ACTION_MOVE:
isClick = false;
moveX = ev.getX();
moveY = ev.getY();
int offsetX = (int) (moveX - downX);
int offsetY = (int) (moveY - downY);
//这里使用了setTranslation来移动view。。。尝试过layout。不知道为什么fragment切换回来的时候会恢复原位
floatingActionButton.setTranslationX(floatingActionButton.getTranslationX() + offsetX);
floatingActionButton.setTranslationY(floatingActionButton.getTranslationY() + offsetY);
break;
case MotionEvent.ACTION_UP:
//用来触发点击事件
if (isClick) {
startAct();
return false;
}
//用来判断移动边界
if (floatingActionButton.getX() < 0) {
floatingActionButton.setX(0);
}
if (floatingActionButton.getX() + floatingActionButton.getWidth() > ScreenUtil.getScreenWidth(getContext())) {
floatingActionButton.setX(ScreenUtil.getScreenWidth(getContext()) - floatingActionButton.getWidth());
}
if (floatingActionButton.getY() < titleHeight) {
floatingActionButton.setY(0);
}
if (floatingActionButton.getY() + floatingActionButton.getHeight() + titleHeight >
getActivity().findViewById(R.id.activity_main_mainLl).getHeight() - getActivity().findViewById(R.id.fc_rg).getHeight()) {
floatingActionButton.setY(getBottomY());
}
break;
}
return true;
}
private void startAct() {
//跳转Activity,传递动画参数
Intent intent = new Intent(getActivity(), CheckWorkActivity.class);
intent.putExtra("x", (int) floatingActionButton.getX() + floatingActionButton.getWidth() / 2);
intent.putExtra("y", (int) floatingActionButton.getY() + floatingActionButton.getHeight() / 2);
intent.putExtra("start_radius", floatingActionButton.getWidth() / 2);
intent.putExtra("end_radius", DialogFragment.this.view.getHeight());
startActivity(intent);
}
});
private void initAnimation() {
//ll为根布局
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll);
linearLayout.post(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Animator animator = ViewAnimationUtils.createCircularReveal(
linearLayout,// 操作的视图
getIntent().getIntExtra("x", 0), // 动画的中心点X
getIntent().getIntExtra("y", 0) + findViewById(R.id.title).getHeight(), // 动画的中心点Y
getIntent().getIntExtra("start_radius", 0), // 动画半径
getIntent().getIntExtra("end_radius", 0) // 动画结束半径
);
animator.setInterpolator(new AccelerateInterpolator());
animator.setDuration(500);
animator.start();
}
}
});
}
private void endAnim() {
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Animator animator = ViewAnimationUtils.createCircularReveal(
linearLayout,// 操作的视图
getIntent().getIntExtra("x", 0),
getIntent().getIntExtra("y", 0) + findViewById(R.id.title).getHeight(),
getIntent().getIntExtra("end_radius", 0),
getIntent().getIntExtra("start_radius", 0)
);
animator.setInterpolator(new AccelerateInterpolator());
animator.setDuration(500);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
finish();
}
});
animator.start();
}
}
<style name="AppThemeCircleRevel" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/blue</item> <item name="android:windowAnimationStyle">@null</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsTranslucent">true</item> <item name="android:colorBackgroundCacheHint">@null</item> </style>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有