Android图片动画。图片从上到下显示

时间:2015-10-19 14:11:26

标签: android image animation

我想要显示图像,但这张图像会从上到下慢慢显示出来。你可以想象如果这个图像是文本,那么这个文本将逐行显示。并且每条线都通过淡化效果显示出来。反正有没有这样做?我甚至不知道应该搜索哪个词。

2 个答案:

答案 0 :(得分:1)

我知道有一种方法可以做到这一点,这很简单,就是使用名为TransitionManager的类。

这是一个简单的代码,您可以将其放在onCreate上并进行测试。

    final ImageView image = new ImageView(this);
        image.setImageResource(R.mipmap.ic_launcher);

    // Set the initial position of the image
    RelativeLayout.LayoutParams imageDetails = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT
    );
    imageDetails.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    imageDetails.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);

    final ViewGroup layout = (ViewGroup)findViewById(R.id.mainLayout);
    layout.setOnTouchListener(new ViewGroup.OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            // Use the default transition of TransitionManager
            TransitionManager.beginDelayedTransition(layout);

            // Set the final position of the image
            RelativeLayout.LayoutParams imageDetails = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT
            );
            imageDetails.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
            imageDetails.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
            image.setLayoutParams(imageDetails);

            return true;
        }
    });

    layout.addView(image, imageDetails);

使用这种方法时我知道一个缺点。最低SDK版本应为19。

PS:如果你想要更多地控制你所做的过渡或动画。请继续阅读Android上的动画和过渡。

答案 1 :(得分:0)

好的,如果你想将视图从上到下移动,你可以使用动画师来设置动画。如果你想从上到下显示图像,那么你可以通过一个技巧来做到这一点。拥有图像视图并在其中加载图像。现在有了另一种观点。所有你需要的是为该视图的高度设置动画,直到顶部与底部重合。你将有你的揭示动画。

如果要创建具有淡入淡出效果的显示,则可以在顶部屏蔽视图并为蒙版设置动画。我过去用这个来创造圆形透视。对于蒙版视图,请看一下:https://github.com/christophesmet/android_maskable_layout

相关问题