ScrollView内部的回收视图项不滚动



我有一个MetarialCardView,它在RecyclerView的列表项中有一定的高度,我在这个MetarialCardView中有一个scrollView。我想在ScrollView中放一长段文本来滚动,但它没有滚动。除此之外,典型的MaterialCardView是可点击的,但有了scrollView,它也失去了可点击性。

我很感激你能提供的任何帮助。

<com.google.android.material.card.MaterialCardView 
android:layout_width="match_parent"
android:layout_height="130dp"
app:cardCornerRadius="12dp"
app:strokeColor="@color/primary_text_color_50"
app:strokeWidth="0.5dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clContract"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivCompleted"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:src="@drawable/ic_completed"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvContract"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:fontFamily="@font/gotham_rounded_bold"
android:textColor="@color/primary_text_color"
android:textSize="@dimen/text_12"
app:layout_constraintEnd_toStartOf="@+id/ivCompleted"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Agreement" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<View
android:id="@+id/viewGradient"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="bottom"
android:background="@drawable/shape_gradient_bottom_separator" />
</com.google.android.material.card.MaterialCardView>

尝试使用NestedScrollview代替ScrollView在xml和以下代码在java文件

recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
int action = e.getAction();
switch (action) {
case MotionEvent.ACTION_MOVE:
rv.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});

试试这个。我还从滚动视图中删除了图标如果你想滚动它只是把它放在滚动视图中。

点击,我认为你可以在itemView上设置点击监听器或者把id赋给cardview然后在上面设置click listener

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="130dp"
app:cardCornerRadius="12dp"
app:strokeColor="@color/primary_text_color_50"
app:strokeWidth="0.5dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/viewGradient"
app:layout_constraintEnd_toStartOf="@+id/ivCompleted"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clContract"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/tvContract"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="8dp"
android:fontFamily="@font/gotham_rounded_bold"
android:textColor="@color/primary_text_color"
android:textSize="@dimen/text_12"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="AgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreementAgreement" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<ImageView
android:id="@+id/ivCompleted"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:src="@drawable/ic_completed"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/viewGradient"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="bottom"
android:background="@drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

最新更新