Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RecyclerView支架始终为包裹内容_Android_Android Recyclerview - Fatal编程技术网

Android RecyclerView支架始终为包裹内容

Android RecyclerView支架始终为包裹内容,android,android-recyclerview,Android,Android Recyclerview,我有一个recyclerview布局: <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".

我有一个recyclerview布局:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.ContactFragment">

<data>

    <variable
        name="vm"
        type="corp.br.UserInfoViewModel" />


</data>

<androidx.constraintlayout.widget.ConstraintLayout
    android:padding="@dimen/default_margin"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:text="@string/account_destination_label"
        android:id="@+id/accountDestinationTv"
        style="@style/DefaulAppearance.Title"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/contactsRv"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        android:layout_marginTop="@dimen/default_margin"
        app:layout_constraintTop_toBottomOf="@+id/accountDestinationTv"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_width="match_parent"
        android:layout_height="0dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

我有一个支架:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".adapter.holder.BaseHolder">

<data>
    <variable
        name="name"
        type="String" />
</data>

<TextView
    android:id="@+id/item_contact_name"
    android:text="@{name}"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/default_margin"
    style="@style/DefaulAppearance"
    tools:text="teste"
    />

</layout>

出于某种原因,当我使用布局检查器时,每个持有者项都具有wrap_content属性,单击仅在我单击文本而不是整行时有效。我的片段有这个recyclerview,它不会对大小做任何更改,适配器和viewholder会做任何更改


有人能告诉我出了什么问题吗?

我找到了解决办法。。。问题是关于线性布局经理的

导致我的问题的默认LinearLayoutManager代码:

@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
    return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
}
我在片段中应用的解决方案:

bind.contactsRv.layoutManager = object : LinearLayoutManager(this@ContactFragment.context) {
        override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
            return RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT)
        }
    }

我只是在LayoutParams的第一个参数中覆盖了
ViewGroup.LayoutParams.WRAP_CONTENT
。我怀疑您没有正确地扩展viewholder的项目视图。它应该看起来像
inflate(R.layout.foo,parent,false)
,而不像
inflate(R.layout.foo,null)
。这就是问题所在吗?