Android:使用新活动切换屏幕或仅更改内容视图 [英] Android: switching screens with new activity or just changing content view

查看:13
本文介绍了Android:使用新活动切换屏幕或仅更改内容视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个游戏,当战斗结束时,我将从主屏幕转到战斗屏幕,然后返回.将两个屏幕作为单独的活动是否更好,或者我可以使用 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().在同一 Activity 中切换布局的正常方法是使用 ViewFlipper 或 FrameLayout(参见 调用 setContentView()多次如何在Android中制作动态翻转屏幕(如iPhone))

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,它似乎非常适合您的需求.http://inphamousdevelopment.wordpress.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/

这篇关于Android:使用新活动切换屏幕或仅更改内容视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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