淡入Android的启动活动 [英] Fade In Android Launch Activity

查看:148
本文介绍了淡入Android的启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找帮助我开展活动褪色。我发现帖子许多关于正在与意向推出的活动,但没有淡出之间关于如何在启动活动褪色。我试过 overridePendingTransition(INT animationIn,诠释animationOut)但是这并没有为我工作。我把它放在了的onCreate(..)方法和在onStart(..)方法,但一直不成功。任何帮助或方向将是AP preciated。

Looking for help fading in my launch activity. I've found LOTS of posts about fading between activities that are being launched with intents, but nothing about how to fade in your launch activity. I've tried overridePendingTransition(int animationIn, int animationOut) but that hasn't worked for me. I've placed it in the onCreate(..) method and the onStart(..) method but have been unsuccessful. Any help or direction would be appreciated.

感谢。

推荐答案

我做的东西了你,它虽然排除了操作栏。
我已经修改了的Hello World演示一点对于一个简单的例子:

I've made something up for you, it excludes the action bar though. I've modified the hello world demo a little for a simple example :


  1. 设置半透明的主题,你的发射活动,我把它叫做Translucy:

  1. Set a translucent theme to your launcher activity, I called it Translucy :

/res/values​​/style.xml

/res/values/style.xml

<style name="Theme.Translucy" parent="android:style/Theme.Translucent">
    <item name="android:windowNoTitle">true</item>
    <item name="android:background">@android:color/transparent</item>
</style>

AndroidManifest.xml中:

AndroidManifest.xml :

<activity
    android:name=".MainActivity"
    android:theme="@style/Theme.Translucy"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


  • 创建主XML布局一个ID,我把它叫做rlayout_main,
    并将其设置为不可见:

  • Create an id for your main xml layout, I called it rlayout_main, and set it to invisible :

    <RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
    
        android:id="@+id/rlayout_main"
        android:visibility="invisible"
        android:background="@android:color/holo_blue_dark"
    
        tools:context=".MainActivity">
    
          <TextView
              android:textSize="50sp"
              android:text="@string/hello_world"
              android:layout_centerInParent="true"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    
    </RelativeLayout>
    


  • 创建AlphaAnimation和动画主父布局:

  • Create an AlphaAnimation and animate your main parent layout :

     public class MainActivity extends Activity {
    
         @Override
         protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
    
         RelativeLayout relativeLayoutMain = (RelativeLayout) findViewById(R.id.rlayout_main);
         AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
         alphaAnimation.setDuration(3000);
         alphaAnimation.setFillAfter(true);
         relativeLayoutMain.startAnimation(alphaAnimation);
         }
     }
    

    (编辑):
    为了节省一点code,你也可以使用ViewPropertyAnimator动画布局,而不是创建一个AlphaAnimation的:

    (EDIT) : To save a little code you can also use ViewPropertyAnimator to animate your layout instead of creating an AlphaAnimation :

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        RelativeLayout relativeLayoutMain = (RelativeLayout)  findViewById(R.id.rlayout_main);
        relativeLayoutMain.animate().alpha(1).setDuration(3000);
        }
    }
    


  • 希望这会有所帮助,就像我说的不是完美的,因为它排除了动作条,但它可能是一个开始。

    Hope this helps, like I said its not perfect because it excludes the ActionBar, but it might be something to start with.

    这篇关于淡入Android的启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆