我想用一些点创建一个动画,它们从上到下落下。为此,我使用的是平移动画,可以将点图像从上到下移动。但我希望这是连续的,这意味着动画应该重演。
我必须创建一个带有一些点的动画,它们从上到下掉落我将发布gif动画文件,这是我的要求,请任何人指导我如何创建这个? 它从FadeIn动画开始,它在我的代码中正常运行,然后从TOP到BOTTOM以连续动态移动的点,如我发布的gif我在我的代码中没有工作我创建了14个Linearlayouts它们包含7个texviews水平带有可见性。在Oncreate中我已经将其可见性改为VISIBLE并开始FADE IN动画,我将发布我的代码,请有人指导我吗? 我的要求 rain_like_animation
public class MainActivity extends Activity implements AnimationListener {
LinearLayout move_animation, move_animation1, move_animation2,
move_animation3, move_animation4, move_animation5;
Display display;
Point size2;
int width1, height1;
// Animation
Animation animFadein;
TranslateAnimation translateanimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = getWindowManager().getDefaultDisplay();
size2 = new Point();
display.getSize(size2);
width1 = size2.x;
height1 = size2.y;
move_animation = (LinearLayout) findViewById(R.id.move_animation);
move_animation1 = (LinearLayout) findViewById(R.id.move_animation1);
move_animation2 = (LinearLayout) findViewById(R.id.move_animation2);
move_animation3 = (LinearLayout) findViewById(R.id.move_animation3);
// load the animation
animFadein = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_in);
// set animation listener
animFadein.setAnimationListener(this);
// (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
translateanimation = new TranslateAnimation(0.0f, 0.0f, -50.0f, height1);
translateanimation.setDuration(3000);
translateanimation.setRepeatCount(Animation.INFINITE);
translateanimation.setRepeatMode(Animation.RESTART);
translateanimation.setFillAfter(false);
translateanimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationStart", "onAnimationStart");
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationRepeat", "onAnimationRepeat");
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationEnd", "onAnimationEnd");
}
});
move_animation.setVisibility(View.VISIBLE);
move_animation1.setVisibility(View.VISIBLE);
move_animation2.setVisibility(View.VISIBLE);
move_animation3.setVisibility(View.VISIBLE);
// start the Fadein animation
// =============================================
// =============================================
move_animation.startAnimation(animFadein);
move_animation1.startAnimation(animFadein);
move_animation2.startAnimation(animFadein);
move_animation3.startAnimation(animFadein);
}
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// start the translate animation when fade-in stops
move_animation.startAnimation(translateanimation);
move_animation1.startAnimation(translateanimation);
move_animation2.startAnimation(translateanimation);
move_animation3.startAnimation(translateanimation);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splashimage"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/move_animation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/move_animation1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/move_animation2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/move_animation3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:4)
下载此库https://github.com/plattysoft/Leonids
将此添加到您的项目依赖项
然后
new ParticleSystem(RainActivity.this, 80, R.drawable.rain_drop, 10000)
.setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
.setAcceleration(0.00005f, 90)
.emitWithGravity(findViewById(R.id.cloud), Gravity.BOTTOM, 8);