Display new Activity on top of previous Activity

前端 未结 2 1333
-上瘾入骨i
-上瘾入骨i 2021-01-07 05:31

\"enter

I have an Activity A which has a \"down\" button (see image above). When I pre

2条回答
  •  無奈伤痛
    2021-01-07 05:55

    What you need to use, are Fragments.

    Fragments can be used to fill a part of the screen, while doing something else entirely in a different one. In your example you can create a main activity that contains two Fragments. One Fragment controls the "A activity" , the other one controls the "B activity" and the other ones.. By replacing the current Fragment in your "B activity" area with a different one on the press of a button, you can achieve the behavior you are looking for. At least, that's how I did it in an app of mine containing a main content area and a music player. The music player stays in place while the main content changes.

    Sadly I can't provide any example code right now, but here is a tutorialthat should help you get started:

    • Android User Interface Design: Working With Fragments

    In case you are working with an Android version below 3.0, you can use the Compatibility package.

    http://developer.android.com/sdk/compatibility-library.html

    http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/

提交回复
热议问题