You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android启动页:Logo与标语缩放移出屏幕并跳转登录页的问题求助

启动页实现问题与解决方案

问题描述

我想要实现一个启动页,将应用Logo和标语缩放至移出屏幕,之后跳转至登录页面等。现有代码如下:

布局XML代码

<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:orientation="vertical"
    android:gravity="center"
    android:background="#1f1f1d"
    tools:context=".SplashActivity">

    <ImageView
        android:id="@+id/appLogo"
        android:layout_width="340dp"
        android:layout_height="64dp"
        android:contentDescription="TODO"
        android:src="@drawable/applogo" />

    <TextView
        android:id="@+id/appText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="App Slogan"
        android:textSize="25sp"
        android:textColor="#fff"
        android:paddingTop="30dp" />

</LinearLayout>

缩放动画XML代码

<scale
    android:duration="800"
    android:pivotY="50%"
    android:pivotX="50%"
    android:fromYScale="1"
    android:toYScale="3"
    android:fromXScale="1"
    android:toXScale="3" />

Activity代码

public class SplashActivity extends AppCompatActivity {

    ImageView logo;

    TextView text;

    Animation zoom_in;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.splashscreen_layout);

        logo = findViewById(R.id.appLogo);

        text = findViewById(R.id.appText);

        zoom_in = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom_in);

        logo.startAnimation(zoom_in);

        text.startAnimation(zoom_in);

    }

}

请问目前还缺少哪些实现部分,能否提供相关指导?


缺失部分与实现指导

  • 动画结束后的页面跳转逻辑:当前仅执行了缩放动画,没有在动画结束后触发登录页跳转。需要给动画添加监听器,在动画结束回调中启动目标页面。
  • 确保元素完全移出屏幕的动画优化:当前设置的toXScale/toYScale=3不一定能保证在所有屏幕尺寸下完全移出,建议调大缩放值(比如5),同时可配合透明度动画让消失效果更自然。
  • 启动页系统配置优化:
    • 隐藏状态栏和导航栏,实现全屏启动页;
    • 在Manifest中配置SplashActivity为启动页,并设置全屏无ActionBar的主题。
  • 防止重复触发逻辑:避免用户快速重启应用时重复执行动画和跳转,可在生命周期中做简单判断。

修改后的Activity代码

public class SplashActivity extends AppCompatActivity {

    ImageView logo;
    TextView text;
    Animation zoom_in;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 隐藏状态栏和导航栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splashscreen_layout);

        logo = findViewById(R.id.appLogo);
        text = findViewById(R.id.appText);

        zoom_in = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom_in);
        
        // 设置动画结束监听器
        zoom_in.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {}

            @Override
            public void onAnimationEnd(Animation animation) {
                // 跳转至登录页
                Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                startActivity(intent);
                // 结束当前页面,防止返回键回到启动页
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {}
        });

        logo.startAnimation(zoom_in);
        text.startAnimation(zoom_in);
    }
}

优化后的缩放+透明度动画

修改res/anim/zoom_in.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:duration="800"
        android:pivotY="50%"
        android:pivotX="50%"
        android:fromYScale="1"
        android:toYScale="5"
        android:fromXScale="1"
        android:toXScale="5" />
    <alpha
        android:duration="800"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />
</set>

AndroidManifest.xml配置示例

<activity
    android:name=".SplashActivity"
    android:theme="@style/Theme.App.Splash">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity android:name=".LoginActivity" />

全屏主题样式(res/values/styles.xml)

<style name="Theme.App.Splash" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

内容的提问来源于stack exchange,提问作者Learn2Code

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 22:18:13