android - 在上一个 Activity 之上显示新 Activity

标签 android android-layout android-activity

enter image description here

我有一个 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/

相关文章:

android - 带有关闭按钮的自定义对话框

android ant -pre-compile 与 -pre-build

android - 异常 java.lang.RuntimeException : setParameters failed

android - 将背景图像从正常图像淡化为褪色图像

android - 如何通过为每个页面中继背景图像来实现 android view pager?

android - EditText 值被 backpress 上的另一个编辑文本替换

java - 在重复的布局上滚动 - Android

android - 如何在触摸图像时放大/缩小全屏查看图像

java - SQLite 异常 : no such column in Android

java - Android 无法实例化 Activity : Didn't find class on path