2015-08-20 56 views
0

在嘗試調用此方法時出現以下異常。在Android應用程序中打開彈出窗口時出現異常

在異常回調的MessageQueue:handleReceiveCallback 08-21 00:12:43.454 10843-10843/common.barter.com.barterapp E /的MessageQueue-JNI:android.view.InflateException:二進制XML文件 線#2:在android.view處com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 處的android.view.LayoutInflater.createView(LayoutInflater.java:633) 處的類 錯誤。 LayoutInflater.onCreateView(LayoutInflater.java:682) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) at android.view.LayoutInf later.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> 
+0

你可以請你發佈佈局文件,你試圖膨脹? – Anytoe

+0

@anytoe更新了帖子。 – pagalpanda

+0

如果我改變顏色而沒有錯誤,例如:android:background =「#FFFFFF」,我可以在屏幕中間看到一個小的彈出窗口,所以也許你的問題應該更好:爲什麼這個顏色不適用於彈出? – Anytoe

回答

0

更改您的代碼:

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'。對於我來說,它現在在屏幕中間以白色背景顯示正常。

相關問題