Android:弹出窗口不会显示内容

时间:2012-06-22 06:35:48

标签: android popup popupwindow

我有一个弹出窗口,应该显示两个按钮和一个带有这个xml的文本视图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/pe"
    android:paddingTop="100dp"
    android:paddingBottom="100dp"
    android:paddingLeft="180dp"
    android:paddingRight="180dp"
    android:background="#444444"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textSize="26dp"
        android:text="Are you sure?" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/bYesClear"
            android:layout_width="86dp"
            android:layout_height="wrap_content"
            android:text="Yes" />

        <Button
            android:id="@+id/bNoClear"
            android:layout_width="86dp"
            android:layout_height="wrap_content"
            android:text="No" />

    </LinearLayout>

</LinearLayout>

这段代码叫它:

private PopupWindow pw;
    private void initiatePopupWindow() {
        try {
            LayoutInflater inflater = (LayoutInflater) Options.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.popupareyousure, (ViewGroup) findViewById(R.id.pe));
            pw = new PopupWindow(layout, 470, 300, true);
            pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

            yesClearButton = (Button) layout.findViewById(R.id.bYesClear);
            noClearButton = (Button) layout.findViewById(R.id.bNoClear);
            yesClearButton.setOnClickListener(this);
            noClearButton.setOnClickListener(this);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

它会以正确的大小显示弹出窗口,但是,它不显示文本视图,也不显示其中的按钮。

0 个答案:

没有答案
相关问题