【发布时间】:2019-10-19 21:44:58
【问题描述】:
我有这个布局和一个 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>
由于某种原因,当我使用 Layout Inspector 时,每个持有者项目都具有 wrap_content 属性,并且单击仅在我单击文本而不是整行时才有效。我的片段有这个 recyclerview 不会对大小做任何改变,更靠近适配器和视图。
谁能告诉我怎么了?
【问题讨论】:
-
我在下面看到了您的答案,但这不是必需的。我怀疑你没有正确地膨胀你的视图持有者的项目视图。它应该看起来像
inflate(R.layout.foo, parent, false)而不是inflate(R.layout.foo, null)。是这个问题吗?
标签: android android-recyclerview