图像在Java中褪色

时间:2016-01-16 07:35:26

标签: java android methods

我在尝试在Android Studio中进行交叉淡入淡出时遇到问题。首先,我有以下代码在两个图像之间进行交叉淡入淡出。代码工作正常。

public class MainActivity extends AppCompatActivity {

        public void fade(View view) {
            ImageView front = (ImageView) findViewById(R.id.front);
            ImageView image1 = (ImageView) findViewById(R.id.image1);
            front.animate().alpha(0f).setDuration(1000);
            image1.animate().alpha(1f).setDuration(1000);
            image1.bringToFront();


        }

        public void fade1(View view) {
            ImageView front = (ImageView) findViewById(R.id.front);
            ImageView image1 = (ImageView) findViewById(R.id.image1);
            image1.animate().alpha(0f).setDuration(2000);
            front.animate().alpha(1f).setDuration(2000);
            front.bringToFront();

        }

但是,当我尝试使用三个图像进行相同的淡入淡出时,代码无法正常工作。它没有正确淡化图像。这是代码:

public void fade(View view) {
        ImageView front = (ImageView) findViewById(R.id.front);
        ImageView image1 = (ImageView) findViewById(R.id.image1);
        front.animate().alpha(0f).setDuration(1000);
        image1.animate().alpha(1f).setDuration(1000);
        image1.bringToFront();
    }

    public void fade1(View view) {
        ImageView image1 = (ImageView) findViewById(R.id.image1);
        ImageView image2= (ImageView) findViewById(R.id.image2);
        image1.animate().alpha(0f).setDuration(1000);
        image2.animate().alpha(1f).setDuration(1000);
        image2.bringToFront();

    }

    public void fade2(View view) {
        ImageView front = (ImageView) findViewById(R.id.image1);
        ImageView image2= (ImageView) findViewById(R.id.image2);
        image2.animate().alpha(0f).setDuration(1000);
        front.animate().alpha(1f).setDuration(1000);
        front.bringToFront();

    }

不确定出了什么问题。任何建议将不胜感激。谢谢

0 个答案:

没有答案