[英]ScrollView inside recycler view item is not scrolling
I have MetarialCardView which has a certain height inside of RecyclerView's list item and I have a scrollView inside this MetarialCardView.我有 MetarialCardView,它在 RecyclerView 的列表项中有一定的高度,我在这个 MetarialCardView 中有一个 scrollView。 I want to scroll by putting a long text in the ScrollView, but it is not scrolling.
我想通过在 ScrollView 中放置一个长文本来滚动,但它没有滚动。 Besides that typically MaterialCardView is clickable, but with scrollView, it is losing its clickability too.
除了通常的 MaterialCardView 是可点击的,但是对于 scrollView,它也失去了可点击性。
I appreciate any help you can provide.感谢您提供的任何帮助。
<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>
Try using NestedScrollview instead ScrollView in xml and below code in java file尝试在 xml 中使用 NestedScrollview 而不是 ScrollView 并在 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) {
}
});
Try this one.试试这个。 I also removed the icon from scroll view if you want to scroll that to just put it inside the scrollview.
如果你想滚动它只是把它放在滚动视图中,我也从滚动视图中删除了图标。
for click i think you can set click listener on itemView or just give id to cardview and set click listener on that.对于点击,我认为您可以在itemView上设置点击监听器,或者只是将 id 提供给 cardview 并在其上设置点击监听器。
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.