寻找帮助在我的发布活动中消失.我发现了许多关于在使用意图启动的活动之间淡出的帖子,但没有关于如何淡化你的启动活动的帖子.我尝试过,overridePendingTransition(int animationIn, int animationOut)但这对我没用.我把它放在onCreate(..)方法和onStart(..)方法中,但都没有成功.任何帮助或方向将不胜感激.
谢谢.
我为你做了一些事,但它排除了动作栏.我为一个简单的例子稍微修改了hello world演示:
将半透明主题设置为您的启动器活动,我称之为Translucy:
/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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)为您的主xml布局创建一个id,我称之为rlayout_main,并将其设置为不可见:
<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>
Run Code Online (Sandbox Code Playgroud)创建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);
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(3000);
alphaAnimation.setFillAfter(true);
relativeLayoutMain.startAnimation(alphaAnimation);
}
}
Run Code Online (Sandbox Code Playgroud)
(编辑):要保存一些代码,您还可以使用ViewPropertyAnimator为布局设置动画,而不是创建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);
}
}
Run Code Online (Sandbox Code Playgroud)希望这有帮助,就像我说它不完美,因为它排除了ActionBar,但它可能是一个开始的东西.
| 归档时间: |
|
| 查看次数: |
2253 次 |
| 最近记录: |