Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

user interface - 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>

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.

Ultimately, I simply want to create a popup, but I do not want to use an AlertDialog. Is this possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...