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
379 views
in Technique[技术] by (71.8m points)

android popup layout over the whole screen

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/popup_bg"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Popup"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:text="This is a simple popup" />

    <Button
        android:id="@+id/close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:text="Close" />

</LinearLayout>

this is my xml layout for popup. But i want that this layout is almost over the whole screen not just so small. How can i extend it? I call it by the code.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

use

android:layout_width="match_parent"
android:layout_height="match_parent"

in LinearLayout

final Dialog dialog = new Dialog(MainAppActivity.this, R.style.PopupDialog);
dialog.setContentView(R.layout.popup);
dialog.setCancelable(true);
Button cancelButton = (Button)dialog.findViewById(R.id.close);
cancelButton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        dialog.cancel();
    }
});

dialog.show();

Put this in res/values/styles.xml

<style name="PopupDialog" parent="@android:style/Theme.Translucent.NoTitleBar"></style>

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

...