Android动态更改布局
我的情况是,我想在3秒钟后更改活动的布局。我能做到吗? 例如,应用程序以运行3秒的splashscreen启动,然后自动将布局切换到应用程序的第一个屏幕布局。这应该发生在同一个活动中,有什么想法吗Android动态更改布局,android,android-activity,Android,Android Activity,我的情况是,我想在3秒钟后更改活动的布局。我能做到吗? 例如,应用程序以运行3秒的splashscreen启动,然后自动将布局切换到应用程序的第一个屏幕布局。这应该发生在同一个活动中,有什么想法吗 谢谢也许您可以使用postDelayed()-调用来执行runnable,它将通过调用setContentView(R.xml.anotherxml)来加载新的xml文件。只需使用ViewSwitcher,使用此选项可以在应用程序中任意数量的布局之间切换,而无需执行任何setContentView。我
谢谢也许您可以使用postDelayed()-调用来执行runnable,它将通过调用setContentView(R.xml.anotherxml)来加载新的xml文件。只需使用ViewSwitcher,使用此选项可以在应用程序中任意数量的布局之间切换,而无需执行任何setContentView。我只使用了一个xml布局。我只是在它里面放了一个额外的RelativeLayout,它代表我的介绍屏幕,然后我在上面使用淡出动画,然后调用.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>
您可以将startAnimation()和setVisibility放在runnable中,并使用markus提到的postDelayed()在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"/>
这让我在adnorid的帖子中补充说,ViewSwitcher本身只能在2个布局/视图之间切换。这仅仅是因为据我所知,它只硬编码为2个布局/视图,没有更深的含义。因此,我构建了自己的MultipleViewSwitcher又名MVS,它基于android源代码中最初的ViewSwitcher.java。必须进行的唯一更改是:
- 布尔mFirstTime和
- int mWhichChild
- addView(…)
- getNextView()
- 重置()
干杯
R.anim.
中的.anim.
在哪里?我得到一个动画无法解析或不是字段
@w0rldart您需要将fadeout.xml添加到/res/anim/
文件夹,请参见我的编辑。
<?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"/>