安卓:开关有新活动的屏幕或只是改变内容视图 [英] Android: switching screens with new activity or just changing content view

查看:101
本文介绍了安卓:开关有新活动的屏幕或只是改变内容视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个游戏,我会从我的主屏幕到战斗画面和回来时,战斗结束。它是更好地有两个屏幕作为单独的活动,或者我可以使用的setContentView(R.layout.screen2)?

I am making a game where I will go from my main screen to a battle screen and the back when the battle is finished. Is it better to have the two screens as separate activities or can I get by using the setContentView(R.layout.screen2)?

我一直试图让该活动画面的切换工作,但每次我尝试它,我的电话告诉我,该应用程序没有响应。如果这是更好地利用活动,然后我会花时间去解决问题,但现在我会采取最简单的方式把事情的工作。

I've been trying to get the activity screen switching to work but everytime I try it, my phone tells me that the app isn't responding. If it is better to use the activities, then I'll take the time to work it out, but for now I'll take the easy way out to get things working.

推荐答案

调用的setContentView()多次不推荐。以正常的方式在相同的活性的布局之间进行切换是使用ViewFlipper或的FrameLayout(见调用的setContentView()多次和<一href="http://stackoverflow.com/questions/2666966/how-can-i-make-a-dynamic-flipping-screenlike-that-of-iphone-in-android">How我可以做一个动态的翻转屏(像iPhone的)在Android中)

Calling setContentView() multiple times is not recommended. The normal way to switch between layouts in the same activity is to use a ViewFlipper or FrameLayout (see Calling setContentView() multiple times and How can i make a dynamic flipping screen(like that of iPhone) in Android)

另外,您可以使用ViewSwitcher,这似乎符合您的需求pretty的好。有可用的好详细的教程,在<一个href="http://inphamousdevelopment.word$p$pss.com/2010/10/11/using-a-viewswitcher-in-your-android-xml-layouts/">http://inphamousdevelopment.word$p$pss.com/2010/10/11/using-a-viewswitcher-in-your-android-xml-layouts/

Alternatively you could use ViewSwitcher, which seems to fit your needs pretty well. There's a good detailed tutorial available at http://inphamousdevelopment.wordpress.com/2010/10/11/using-a-viewswitcher-in-your-android-xml-layouts/

这篇关于安卓:开关有新活动的屏幕或只是改变内容视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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