问题描述
我正在创建一个Android应用,其中有人可以输入他们的名字,按一个按钮,然后它只是将他们的名字输回给他们。
I am currently creating an Android app where someone can input their name, press a button, and then it just outputs their name back to them.
一个效果我希望实现这一效果,在按下按钮后,输入和按钮将消失(到目前为止完成此位),然后MainActivity视图的背景颜色将产生波纹(从中心)使用新颜色,最终改变整个背景颜色。
One effect that I would like to achieve with this is an effect where, after they push the button, the input and button will vanish (complete this bit so far), and then the background colour of the MainActivity's view will do a ripple (from the centre) with a new colour, eventually changing the full background colour.
我将如何以编程方式执行此操作,因为我只能找到有关向按钮添加涟漪的教程推?
How would I go about doing this programatically, since I am only able to find tutorials on adding ripples to buttons when pushed?
推荐答案
编辑:
我通过制作一个小应用程序测试了这个
I tested this by making a small app
首先隐藏你想在这个动画中显示的视图。
First of all hide the view you want to reveal in this animation.
视图可以来自相同的布局,在xml中,其可见性应为不可见,以便动画显示al 它。
The view can be from the same layout and in xml its visibility should be invisible so that the animation will reveal it.
如果要创建完整,可以将视图高度和宽度设置为匹配父屏幕动画 ...
You can set the view height and width to match parent if you want to create a full screen animation...
以框架布局
在我的情况下,我使用过这个:
In my case,I have used this:
<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>
然后在您的活动中按钮点击
或有些事件可以这样做:
then in your activity on button click
or some event do this:
fab.setOnClickListener(new View.OnClickListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View view) {
// previously invisible view
View myView = findViewById(R.id.revealview);
// 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);
//Interpolator for giving effect to animation
anim.setInterpolator(new AccelerateDecelerateInterpolator());
// Duration of the animation
anim.setDuration(1000);
// make the view visible and start the animation
myView.setVisibility(View.VISIBLE);
anim.start();
}
});
}
您可以在此处详细了解官方文档:
You can take detailed look at official documentation here:http://developer.android.com/training/material/animations.html
这篇关于Android:以编程方式提供Ripple背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!