Java Android:未找到属性';headerView&x27;

Java Android:未找到属性';headerView&x27;,java,android,android-layout,Java,Android,Android Layout,使用Android Studio,我在活动布局中遇到以下错误:error:(9)在“com.merahjambutech.zuki.deteksi”包中找不到属性“headerView”的资源标识符 <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" xml

使用Android Studio,我在活动布局中遇到以下错误:
error:(9)在“com.merahjambutech.zuki.deteksi”包中找不到属性“headerView”的资源标识符

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    xmlns:compat="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <com.merahjambutech.zuki.deteksi.view.PullToZoomListViewEx
        android:id="@+id/paralax_social_list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@android:color/transparent"
        app:headerView="@layout/header_parallax_social" />
</LinearLayout>

我非常确定我的项目文件(res/layout)中有布局header\u parallax\u social.xml,下面是header\u parallax\u social的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="160dp" >

    <ImageView
        android:id="@+id/header_parallax_social_new_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_centerVertical="true"
        android:layout_gravity="center_horizontal"
        android:contentDescription="@string/cd_main_image"
        android:scaleType="centerCrop"
        android:src="@drawable/parallax_social_small" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:orientation="vertical" >
    </LinearLayout>

</RelativeLayout>


我试图更改xmlns:app和类似的内容,但仍然没有找到解决方案…

您必须在
attrs.xml
values
文件夹中为您的
Listview
设置自定义属性,即headerView:

attrs.xml

 <resources>
<declare-styleable name="PullToZoomListViewEx">  declare your custom listview class name here
    <attr name="headerView" format="reference"/>
</declare-styleable>
 </resources>

如果要避免上述工作,可以通过编程方式将标题视图设置为Listview,如下所示:

   LayoutInflater inflater = getLayoutInflater();
   ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header,myListView, false);
//replace  R.layout.header with R.layout.header_parallax_social and  myListView with your listview object
   myListView.addHeaderView(header, null, false);

希望这能有所帮助。

我认为您应该使用可绘制而不是布局。=><代码>应用程序:headerView=“@drawable/header\u parallax\u social”或尝试更改
xmlns:app=”http://schemas.android.com/apk/res-auto
xmlns:app=”http://schemas.android.com/tools
   LayoutInflater inflater = getLayoutInflater();
   ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header,myListView, false);
//replace  R.layout.header with R.layout.header_parallax_social and  myListView with your listview object
   myListView.addHeaderView(header, null, false);