【发布时间】:2015-02-27 09:55:49
【问题描述】:
有什么方法可以在 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);
【问题讨论】:
-
你想用 Java 还是 Android 来做?
-
使用 AnimationDrawable (Rotation) 作为 Button 父级的背景。 developer.android.com/guide/topics/resources/…
-
你好@Juwei ...你找到解决方案了吗?!
标签: android android-animation android-button