我有一个 Activity A,它有一个“向下”按钮(见上图)。当我按下这个按钮时,我想在 Activity A 的顶部启动一个 Activity B,这样底部的一些 Activity A 仍然可见。 Activity B 可以依次启动许多其他 Activity(C、D 等),但它们只能显示在与 B 相同的屏幕区域内。任何人都知道这是否可能以及我该如何去做?
Edit: I am aware that I can add
android:theme="@android:style/Theme.Dialog"
to my Activity manifest but as far as I am aware this displays in the centre of the screen and not such that I can resize it how I like. Correct me if I am wrong...
最佳答案
这是应该位于 Activity a 之上的 Activity 的 xml
<?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>
现在在 Activity B、C 等的 list 中:
<activity
android:label="@string/app_name"
android:name=".ActivityB"
android:theme="@style/Theme.Transparent"
android:screenOrientation="portrait" >
在 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>
最后在 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>
关于android - 在上一个 Activity 之上显示新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8503653/