Java 自定义布局不显示
我正在尝试制作一个可重复使用的标题。这是我的XMLJava 自定义布局不显示,java,android,android-layout,Java,Android,Android Layout,我正在尝试制作一个可重复使用的标题。这是我的XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:backgroun
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg" >
<ImageButton
android:id="@+id/imagebuttonforheader"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_alignParentLeft="true"
android:background="@drawable/back_button"
/>
<ImageButton
android:id="@+id/imagebuttonforheader"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_alignParentRight="true"
android:background="@drawable/forward_button"
/>
</RelativeLayout>
然后将此布局添加到my main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<my.testy.view.Header
android:id="@+id/headerOnMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
</my.testy.view.Header>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/headerOnMain"
android:text="@string/hello" />
</RelativeLayout>
但它没有出现在应用程序上
我做错了什么?您必须将充气布局附加到自定义类:
li.inflate(R.layout.header, this, true);
谢谢成功了。真不敢相信我竟然忘了这个。它已经折磨了我好几个小时了@普罗米修斯87我也看不到你的整个
R.layout.header
,但是看看这篇文章(如果你还没有做过的话)->
li.inflate(R.layout.header, this, true);