繁体   English   中英

在Android应用中打开弹出窗口时发生异常

[英]Exception while opening popup window in Android app

尝试调用此方法时,出现以下异常。

MessageQueue回调中的异常:handleReceiveCallback 08-21 00:12:43.454 10843-10843 / common.barter.com.barterapp E / MessageQueue-JNI:android.view.InflateException:二进制XML文件第2行:在Android上夸大类的错误。 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)的android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)的view.LayoutInflater.createView(LayoutInflater.java:633) android.view.LayoutInflater.inflate(LayoutInflater.java:482)上的.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)android.view.LayoutInflater上的.view.LayoutInflater.inflate(LayoutInflater.java:414)。充气(LayoutInflater.java:365)

public class GlobalHome extends ActionBarActivity{
----------------------
----------------------
private void showLocationPopup() {

    LayoutInflater inflater = (LayoutInflater)
            this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.popup_location,
            (ViewGroup) findViewById(R.id.layout_location_popup));
    PopupWindow pw = new PopupWindow(
            layout,
            100,
            100,
            true);
    // The code below assumes that the root container has an id called 'main'
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

}
}

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/switch_thumb_material_light"
android:id="@+id/layout_location_popup"
>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:text="Test Pop-Up"
    />

</LinearLayout>

将您的代码更改为:

private void showLocationPopup() {

    LayoutInflater inflater = (LayoutInflater)
            getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.popup_location,(ViewGroup) getActivity().findViewById(R.id.layout_location_popup));
    PopupWindow pw = new PopupWindow(
            layout,
            100,
            100,
            true);
    // The code below assumes that the root container has an id called 'main'
    pw.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:id="@+id/layout_location_popup">

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:text="Test Pop-Up"/>
</LinearLayout>

我更改了颜色,因为您选择的颜色不起作用。 对我来说似乎不是典型的android颜色。 此外,我将布局的宽度和高度设置为“ WRAP_CONTENT”。 对我来说,它现在在屏幕中间显示为白色,显示良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM