Android的 - 活动不填充父屏幕 [英] Android - Activity that does not fill the parent screen
问题描述
为什么不创建,看起来像一个弹出窗口,而不是一个活动,完全填充屏幕的活动你知道吗?
Any idea why this doesn't create an activity that looks like a popup instead of an activity that completely fills the screen?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="300dip"
android:layout_height="120dip"
android:layout_marginTop="100dip">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="120dip"
android:layout_width="300dip">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</RelativeLayout>
</LinearLayout>
我认为我只需要设置布局的高度和布局宽度为除FILL_PARENT等,但它仍然显示为黑色的屏幕,完全充满屏幕。
I assumed that I only needed to set the layout height and layout width to something other than "fill_parent", but it still shows up as a black screen that completely fills the screen.
最后,我只是想创建一个弹出,但我不希望使用一个AlertDialog。这可能吗?
Ultimately, I simply want to create a popup, but I do not want to use an AlertDialog. Is this possible?
推荐答案
您必须将你的活动窗口进行浮动。你可以做到这一点无论是给你的活性的Android(安卓风格/ Theme.Dialog
)中定义的对话风格,也可以定义自己的风格,像这样的:
You must set your Activity's window to be floating. You can do this either by giving your activity the Dialog style defined by Android (android:style/Theme.Dialog
), or define your own style, like this:
<style name="MyFloatingWindow">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
</style>
然后设置样式您在应用程序的清单活动。
Then set the style on your activity in the application's Manifest.
这篇关于Android的 - 活动不填充父屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!