我想要在片段上加载动画屏幕,如启动屏幕

时间:2018-09-13 18:44:53

标签: android-studio android-fragments android-animation

我希望在我的应用程序上加载动画,但是我的应用程序大部分都是片段,这是我的代码请帮助我,因为我希望用户看到的第一件事是动画消失一段时间后

    public class MainActivity extends AppCompatActivity implements MainFragment.OnFragmentInteractionListener,ParrablesFragment.OnParFragmentInteractionListener,TortoiseFragment.OnTorFragmentInteractionListener,AeroFragment.OnaeroFragmentInteractionListener,ValueFragment.OnvalFragmentInteractionListener,SecreteFragment.OnSecreteFragmentInteractionListener,
        UglyFragment.OnUglyFragmentInteractionListener,ThreeFragment.OnThreeFragmentInteractionListener,PrincessFragment.OnPrincesFragmentInteractionListener,WiseFragment.OnWiseFragmentInteractionListener
        ,BadFragment.OnBadFragmentInteractionListener,BullyFragment.OnBullyFragmentInteractionListener,RashFragment.OnRashFragmentInteractionListener,SucessFragment.OnSucessFragmentInteractionListener,Page2Fragment.OnPage2FragmentInteractionListener,NewPageFragment.OnNewPFragmentInteractionListener
,Chapter2Fragment.OnChapterFragmentInteractionListener,LV1Fragment.OnLv1FragmentInteractionListener,LV2Fragment.OnLV2FragmentInteractionListener,LV3Fragment.OnLV3FragmentInteractionListener,LV4Fragment.OnLV4FragmentInteractionListener,LV5Fragment.OnLV5FragmentInteractionListener,LV6Fragment.OnLV6FragmentInteractionListener
,LV7Fragment.OnLV7FragmentInteractionListener,LV8Fragment.OnLV8FragmentInteractionListener,LV9Fragment.OnLV9FragmentInteractionListener,LV10Fragment.OnLV10FragmentInteractionListener,LV11Fragment.OnLv11FragmentInteractionListener,Lv12Fragment.OnLV12FragmentInteractionListener,LV13Fragment.OnLv13FragmentInteractionListener
,LV14Fragment.OnLV14FragmentInteractionListener,LV15Fragment.OnLV15FragmentInteractionListener,LV16Fragment.OnLV16FragmentInteractionListener,LV17Fragment.OnLV17FragmentInteractionListener,LV18Fragment.OnLV18FragmentInteractionListener,LV19Fragment.OnLV19FragmentInteractionListener,LV20Fragment.OnLV20FragmentInteractionListener
,LV21Fragment.OnLV21FragmentInteractionListener,LV22Fragment.OnLV23FragmentInteractionListener,LV23Fragment.OnLV22FragmentInteractionListener,AdventureFragment.OnADVENTUREFragmentInteractionListener,AV1Fragment.OnAV1FragmentInteractionListener,AV2Fragment.OnAV2FragmentInteractionListener,AV3Fragment.OnAV3FragmentInteractionListener
,AV4Fragment.OnAV4FragmentInteractionListener,AV5Fragment.OnAV5FragmentInteractionListener,AV6Fragment.OnAV6FragmentInteractionListener,AV7Fragment.OnAV7FragmentInteractionListener,AV8Fragment.OnAV8FragmentInteractionListener,AV9Fragment.OnAV9FragmentInteractionListener,AV1OFragment.OnAV10FragmentInteractionListener
,AV11Fragment.OnAV11FragmentInteractionListener,AV12Fragment.OnAV12FragmentInteractionListener,AV13Fragment.OnAV13FragmentInteractionListener,AV14Fragment.OnAV14FragmentInteractionListener,AV15Fragment.OnAV15FragmentInteractionListener,AV16Fragment.OnAV16FragmentInteractionListener,AV17Fragment.OnAV17FragmentInteractionListener
,AV18Fragment.OnAV18FragmentInteractionListener,AV19Fragment.OnAV19FragmentInteractionListener,AV20Fragment.OnAV20FragmentInteractionListener,AV21Fragment.OnAV21FragmentInteractionListener,AV22Fragment.OnAV22FragmentInteractionListener,Av23Fragment.OnAV23FragmentInteractionListener,AV24Fragment.OnAV24FragmentInteractionListener
,MysteryFragment.OnMysteryFragmentInteractionListener,MY1Fragment.OnMy1FragmentInteractionListener,M2Fragment.OnM2FragmentInteractionListener,M3Fragment.OnM3FragmentInteractionListener,M4Fragment.OnM4FragmentInteractionListener,M5Fragment.OnM5FragmentInteractionListener,M6Fragment.OnM6FragmentInteractionListener,M7Fragment.OnM7FragmentInteractionListener
,M9Fragment.OnM9FragmentInteractionListener,M8Fragment.OnM8FragmentInteractionListener,M10Fragment.OnM10FragmentInteractionListener,M11Fragment.OnM11FragmentInteractionListener,M12Fragment.OnM12FragmentInteractionListener,M13Fragment.OnM13FragmentInteractionListener,M14Fragment.OnM14FragmentInteractionListener
,M15Fragment.OnM15FragmentInteractionListener,M16Fragment.OnM16FragmentInteractionListener,M17Fragment.OnM17FragmentInteractionListener,M18Fragment.OnM18FragmentInteractionListener,M19Fragment.OnM19FragmentInteractionListener,M20Fragment.OnM20FragmentInteractionListener,M21Fragment.OnM21FragmentInteractionListener
,M22Fragment.OnM22FragmentInteractionListener,M23Fragment.OnM23FragmentInteractionListener,M24Fragment.OnM24FragmentInteractionListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
        android.support.v4.app.Fragment fragment = manager.findFragmentById(R.id.fragment_container);

        if (fragment == null) {
            fragment = new MainFragment();
            FragmentTransaction transaction = manager.beginTransaction();
            transaction.add(R.id.fragment_container, fragment);
            transaction.commit();


        }
    }

1 个答案:

答案 0 :(得分:2)

使用以下代码制作启动画面:

在res> drawable文件夹内,添加一个标题为splash.xml的新的drawable资源文件

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

<item android:drawable="@color/colorPrimary"/>

<item>
    <bitmap android:src="@drawable/logo"
        android:gravity="center"/>
</item>
</layer-list>

在values> styles.xml中,粘贴以下内容:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
</style>

然后创建一个Java类SplashActivity.java

package com.example.android.motouch3;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
    finish();
}
}

现在,当用户打开应用程序时,带有徽标的启动屏幕将弹出几秒钟,然后恢复到正常屏幕。

相关问题