Java Android:Ripple后台编程
我目前正在创建一个Android应用程序,用户可以输入自己的名字,按下一个按钮,然后将名字输出回用户 我想用它实现的一个效果是,当他们按下按钮后,输入和按钮将消失(到目前为止完成这一点),然后MainActivity视图的背景色将产生一个新颜色的涟漪(从中心),最终改变整个背景色Java Android:Ripple后台编程,java,android,xml,user-interface,Java,Android,Xml,User Interface,我目前正在创建一个Android应用程序,用户可以输入自己的名字,按下一个按钮,然后将名字输出回用户 我想用它实现的一个效果是,当他们按下按钮后,输入和按钮将消失(到目前为止完成这一点),然后MainActivity视图的背景色将产生一个新颜色的涟漪(从中心),最终改变整个背景色 既然我只能找到关于在按下按钮时向按钮添加涟漪的教程,那么我将如何以编程方式进行此操作?您所描述的是一个背景 从官方文档中,您可以找到现成的示例: 1) 以下是如何使用“显示效果”显示以前不可见的视图: // prev
既然我只能找到关于在按下按钮时向按钮添加涟漪的教程,那么我将如何以编程方式进行此操作?您所描述的是一个背景 从官方文档中,您可以找到现成的示例: 1) 以下是如何使用“显示效果”显示以前不可见的视图:
// previously invisible view
View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = myView.getWidth() / 2;
int cy = myView.getHeight() / 2;
// get the final radius for the clipping circle
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
// create the animator for this view (the start radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
// make the view visible and start the animation
myView.setVisibility(View.VISIBLE);
anim.start();
// previously visible view
final View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = myView.getWidth() / 2;
int cy = myView.getHeight() / 2;
// get the initial radius for the clipping circle
int initialRadius = myView.getWidth();
// create the animation (the final radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);
// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
myView.setVisibility(View.INVISIBLE);
}
});
// start the animation
anim.start();
2) 以下是如何使用“显示”效果隐藏以前可见的视图:
// previously invisible view
View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = myView.getWidth() / 2;
int cy = myView.getHeight() / 2;
// get the final radius for the clipping circle
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
// create the animator for this view (the start radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
// make the view visible and start the animation
myView.setVisibility(View.VISIBLE);
anim.start();
// previously visible view
final View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = myView.getWidth() / 2;
int cy = myView.getHeight() / 2;
// get the initial radius for the clipping circle
int initialRadius = myView.getWidth();
// create the animation (the final radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);
// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
myView.setVisibility(View.INVISIBLE);
}
});
// start the animation
anim.start();
在应用程序中,您可以使用彩色背景层(开始时不可见),然后在其上使用显示效果。编辑:
我通过制作一个小应用程序来测试这一点
首先,隐藏要在此动画中显示的视图
视图可以来自同一布局,在xml中,视图的可见性应该是不可见的,这样动画就会显示视图
如果要创建全屏动画,可以将视图高度和宽度设置为匹配父对象
在框架布局中获取原始视图并显示视图
就我而言,我使用了以下方法:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:text="Hello World!"
android:layout_width="wrap_content"
android:textSize="20sp"
android:layout_height="wrap_content" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:id="@+id/revealiew"
android:visibility="invisible"
>
</FrameLayout>
您可以在此处详细查看官方文档:
查看此网站,“Android Ripple Background”是一个库,min sdk是11(Android 3.0蜂巢)
在3小时内设置赏金。你能展示一下你尝试了什么吗?什么都没有。我不知道从哪里开始。我是Android-y的初学者。所以我想首先你需要尝试一下按钮来理解连锁反应的概念。很好的答案。今晚我将尝试一下(当我可以访问AS时),并将其标记为有效答案。我正在积极尝试,赏金将在接下来的10-15分钟内颁发。似乎不是动画,而是让它出现。在这样的示例中,您如何使用XML?@SysVoid您可能做错了什么。开始在带有两个嵌套FrameLayout的空活动上尝试此操作,并使用“显示”效果使内部活动显示/隐藏。在这里看一看@SysVoid在这里看一看您的实现可能存在的问题(es动画持续时间、getWidth调用太早等等):您测试过这个吗?你能把我要求的动画gif包含在赏金中吗?遗憾的是,它不再让我选择你作为赏金赢家的答案了。或者甚至让我给你+25次重复。我会联系工作人员寻求帮助。@VishavjeetSingh我如何在按钮的中心开始圆形显示效果。只需将cx,cy替换为按钮的轴x,y坐标:cx=myButton.getPivotX();cy=myButton.getPivotY();否决票。你从未尝试过遵守赏金规则。