簡體   English   中英

回收站視圖項中的 ScrollView 不滾動

[英]ScrollView inside recycler view item is not scrolling

我有 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>

嘗試在 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) {

    }
});

試試這個。 如果你想滾動它只是把它放在滾動視圖中,我也從滾動視圖中刪除了圖標。

對於點擊,我認為您可以在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM