有没有办法在Android的按钮后面创建光线动画,就像this的javascript-demo。
当单击它时,它应该只是在Button后面旋转,但不应该扩展视图的内容区域(浮动在Button后面)。

光线应该在父布局的矩形内旋转。
有什么简单的方法可以做到吗?
我的代码:
final LinearLayout.LayoutParams LLParamsCont = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, Utils.dpToPx(getContext(), 50));
LLParamsCont.setMargins(Utils.dpToPx(getContext(), 5), Utils.dpToPx(getContext(), 5), Utils.dpToPx(getContext(), 5), Utils.dpToPx(getContext(), 5));
LLParamsCont.gravity = Gravity.CENTER;
RelativeLayout cont = new RelativeLayout(getContext());
cont.setLayoutParams(LLParamsCont);
/* This image view should extend its available space without change the parents dimensions and animate */
ImageView imageView = new ImageView(getContext());
imageView.setImageResource(R.drawable.sunray);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
cont.addView(imageView);
/* Trying it with that code, but the imageview is behind the button and only visible a view pixel
Increasing the parent will be a mess with other buttons, the rays should just overlap a litle bit all other elements in the back.
The final rays will be a more alpha transparent ...*/
Animation rotate = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
imageView.startAnimation(rotate);
Button btn = new Button(getContext());
btn.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
btn.setText("Button");
cont.addView(btn);发布于 2015-02-27 18:03:31
只需创建您自己的动画:按照下面的示例在动画文件夹中创建shake.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="10"
android:duration="1000"
android:interpolator="@anim/cycle" />和cycle.xml在动画文件夹中
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="4" />现在在您的代码中添加动画
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
anyview.startAnimation(shake);如果需要垂直动画,请将fromXdelta和toXdelta值更改为fromYdelta和toYdelta值。
查看this教程。他有不同的动画方式。
希望能对你有所帮助。
https://stackoverflow.com/questions/28762165
复制相似问题