Aya*_*avi 12 android android-activity
我有在3秒后想要改变活动布局的情况.我可以这样做吗?例如,应用程序以启动屏幕启动,运行3秒钟,然后自动将布局切换到应用程序的第一个屏幕布局.这应该发生在同一个活动,任何想法?
谢谢
Foa*_*Guy 14
我只使用一个xml布局.我只是在其中添加了一个代表我的介绍屏幕的额外RelativeLayout然后我在其上使用fadeOut Animation然后调用.setVisibility(View.GONE).
这是我的main.xml布局文件的一部分
<RelativeLayout
android:id="@+id/introLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
<ImageView
android:id="@+id/logoImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/logo">
</ImageView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
然后在我的活动中我有这个:
introLayout = (RelativeLayout) findViewById(R.id.introLayout);
Animation fadeOutAnim = AnimationUtils.loadAnimation(MyActivity.this, R.anim.fadeout);
introLayout.startAnimation(fadeOutAnim);
introLayout.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
您可以通过将startAnimation()和setVisibility放在runnable中并使用postDelayed()作为markus提到3秒后运行.虽然这个介绍布局在屏幕上,但是考虑做一些工作,所以它不仅仅是用户的3秒延迟.也许检查应用程序的运行版本是否是当前版本.
编辑:
您需要添加fadout.xml文件/res/anim/(如果它不存在,则创建anim目录).这是一个例子.
fadeout.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="700"
android:fillAfter="true"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41771 次 |
| 最近记录: |