如何使ImageView部分可见并完全淡入?

时间:2016-11-06 22:30:10

标签: java android xml android-animation

我目前正在制作一个应用程序,我希望应用程序的部分徽标出现在屏幕的中央,转换为顶部,然后显示整个徽标。我目前有应用程序显示整个徽标并根据需要进行翻译,但我不知道如何隐藏大部分徽标并使其显示。我的徽标由左侧的图标和右侧的文本组成。一旦徽标到达顶部,我希望名称显示顺畅,同时将图标向左推。有没有办法使用我当前的代码来做到这一点。

logo_animation.xml:

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">

    <alpha
        android:duration="800"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="1.0" />

    <translate
        android:duration="800"
        android:fillAfter="true"
        android:fromYDelta="0%p"
        android:startOffset="2000"
        android:toYDelta="-30%p" />

</set>

main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="15dp"
    android:paddingStart="15dp"
    android:paddingRight="15dp"
    android:paddingEnd="15dp"
    android:background="@color/colorPrimary"
    tools:context=".Main">

    <ImageView
        android:id="@+id/mainLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:contentDescription="@string/logo"
        android:src="@mipmap/ic_launcher" />

</RelativeLayout>

Main.java:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

public class Main extends AppCompatActivity implements AnimationListener {

    ImageView mainLogo;

    Animation mainLogoAnimation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        searchLogo = (ImageView) findViewById(R.id.searchLogo);

        mainLogoAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.logo_animation);
        mainLogoAnimation.setAnimationListener(this);
    }

    @Override
    public void onAnimationEnd(Animation animation) {

    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }

    @Override
    public void onAnimationStart(Animation animation) {

    }

}

1 个答案:

答案 0 :(得分:-1)

只需将文本放在单独的TextView中,然后单独为其设置动画。

相关问题