LayoutInflater无法通过引用类来扩展布局

时间:2011-05-17 13:08:55

标签: android

我尝试给包含类的布局充气。 我创建了inflater实例:

 LayoutInflater inflate =(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    
mRelLayout = (RelativeLayout) inflate.inflate(
                    R.layout.app_layout, null);  

我的app_layout.xml布局是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
            xmlns:panel="http://schemas.android.com/apk/res/com.alpha"
            android:id="@+id/layoutMain"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" 
            android:gravity="top|right">

             。         。         。            

通货膨胀失败,异常:java.lang.RuntimeException:您的Panel必须有一个子视图,其id属性为'R.id.panelHandle'

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

我试过以下代码,它工作正常,请提供完整的源代码,以便我能识别错误。

Test.java

 LayoutInflater inflate =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);    
     RelativeLayout mRelLayout = (RelativeLayout) inflate.inflate(
                         R.layout.app_layout, null);  

app_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
            xmlns:panel="http://schemas.android.com/apk/res/com.alpha"
            android:id="@+id/layoutMain"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" 
            android:gravity="top|right" />

答案 1 :(得分:0)

您是否尝试删除xmlns:panel="http://schemas.android.com/apk/res/com.alpha"

你可以发布整个布局吗?