【问题标题】:Exception while opening popup window in Android app在 Android 应用程序中打开弹出窗口时出现异常
【发布时间】:2015-11-14 13:22:55
【问题描述】:

我在尝试调用此方法时遇到以下异常。

MessageQueue 回调中的异常:handleReceiveCallback 08-21 00:12:43.454 10843-10843/common.barter.com.barterapp E/MessageQueue-JNI: android.view.InflateException: 二进制 XML 文件 第 2 行:错误膨胀类 在 android.view.LayoutInflater.createView(LayoutInflater.java:633) 在 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 在 android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 在 android.view.LayoutInflater.inflate(LayoutInflater.java:482) 在 android.view.LayoutInflater.inflate(LayoutInflater.java:414) 在 android.view.LayoutInflater.inflate(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>

【问题讨论】:

  • 能否请您发布您要膨胀的布局文件?
  • @anytoe 更新了帖子。
  • 如果我在没有错误的情况下更改颜色,我会在屏幕中间看到一个小弹出窗口,例如:android:background="#FFFFFF",所以也许你的问题应该是:为什么这种颜色不适用于弹出窗口?
  • 感谢@anytoe,但我看不到内容(文本视图)。
  • 请参阅下面的答案,如果它为您解决了问题,请接受

标签: android popupwindow inflate-exception


【解决方案1】:

将您的代码更改为:

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>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多