Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Android应用程序中,如何在图像视图之间淡入淡出?_Java_Android - Fatal编程技术网

Java 在Android应用程序中,如何在图像视图之间淡入淡出?

Java 在Android应用程序中,如何在图像视图之间淡入淡出?,java,android,Java,Android,我知道如何为2个图像执行此操作,但3个图像如何 public void fadeBardock(视图){ ImageView-bardock=(ImageView)findViewById(R.id.bardock); ImageView小悟空=(ImageView)findViewById(R.id.goku); ImageView gohan=(ImageView)findViewById(R.id.gohan); bardock.animate().alpha(0 f).setDurati

我知道如何为2个图像执行此操作,但3个图像如何

public void fadeBardock(视图){
ImageView-bardock=(ImageView)findViewById(R.id.bardock);
ImageView小悟空=(ImageView)findViewById(R.id.goku);
ImageView gohan=(ImageView)findViewById(R.id.gohan);
bardock.animate().alpha(0 f).setDuration(3000);
小悟空.animate().alpha(0 f).setDuration(4000);
gohan.animate().alpha(1f).setDuration(5000);
}
单击按钮后,我将直接获取第三张图像,而不获取第二张图像。

请尝试以下代码:

bardock.animate().alpha(0f).setDuration(3000);
goku.setAlpha(0f);
goku.animate().alpha(1f).setDuration(3000).setStartDelay(1500);
goku.animate().alpha(0f).setDuration(3000).setStartDelay(4500);
gohan.setAlpha(0f);
gohan.animate().alpha(1f).setDuration(3000).setStartDelay(6000);

您可以更改持续时间和启动延迟以获得最佳结果。

在多个ImageView上,
1.创建ImageView的数组。
2.初始化其中的视图。
3.为同一循环中的每个视图分配唯一id

[另一件事是,您可以在onCreate()中的一个for循环中初始化视图,然后单击按钮,为动画应用另一个for循环。]

  • 现在,使用数组索引,将动画指定给每个视图,并与以前的视图进行延迟
  • 循环后启动动画并检查。
    希望能有帮助