安卓:开关有新活动的屏幕或只是改变内容视图视图、屏幕、内容

2023-09-12 07:44:17 作者:长夜未央

我在做一个游戏,我会从我的主屏幕到战斗画面和回来时,战斗结束。它是更好地有两个屏幕作为单独的活动,或者我可以使用的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()多次和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的好。有可用的好详细的教程,在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/