I have an Activity A which has a \"down\" button (see image above). When I pre
This is the xml for activities that should be on top of activity a
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0"
android:layout_weight="0.6"
android:background="#000000" >
//use this for your new activity contents
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0"
android:layout_weight="0.4"
android:background="#00000000" >
//this is empty
</LinearLayout>
</LinearLayout>
Now in your manifest for activity B,C ,... etc:
<activity
android:label="@string/app_name"
android:name=".ActivityB"
android:theme="@style/Theme.Transparent"
android:screenOrientation="portrait" >
in values/styles.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme.NoTitleBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@drawable/theme_transparent</item>
</style>
</resources>
Finally in drawable/theme_transparent.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00000000" ></solid>
</shape>
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:
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/