Using Fragments to switch activities

和自甴很熟 提交于 2019-12-23 04:28:29

问题


I'm trying to create a layout that has a stationary footer with activities that slide behind it. I've been told to use Fragments, but that would mean that I would have to convert my already existing Activities to Fragments - right? Here is a diagram of what I'm trying to achieve: http://i.imgur.com/K8Iao.jpg


回答1:


What I think @TarunMaheshwari is trying to say is that instead of having 3 activities (eg. classes with extends activity), replace it with extends fragment (obviously there are other minor changes you might have to make for the code to work) and then create a main activity (with extends FragmentActivity) that has the static footer you want which can call on the 3 different fragments.

Recommended readings:

http://developer.android.com/guide/topics/fundamentals/fragments.html

http://android-developers.blogspot.ca/2011/02/android-30-fragments-api.html




回答2:


I believe using fragments is the right solution for your app. However, from what I understand from your question and comments, you really want to avoid using them. To use activities instead of fragments, implement a Tab Layout with a Tab Host and Tab Widget as explained in this tutorial. This solution allows you to use the tabs to switch between activities.

To align the Tab Host to the bottom of the screen, have a look at this tutorial.



来源:https://stackoverflow.com/questions/10574790/using-fragments-to-switch-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!