Recyclerview溢出ConstraintLayout

问题描述 投票:0回答:1

我正在尝试创建一个recyclerview,该视图的大小会随着其他项目的增加而增大,直到达到一定的最大高度,然后逐渐消失。我知道约束布局是到达此处的正确方法,我发誓这个约束已经在一个月前开始工作,然后Recyclerview不再关心约束并在280dp以上可见(请参见图片)。这是我的代码。我确定这已经在工作,我不知道Google是否将某些东西更改为实现“ androidx.constraintlayout:constraintlayout:2.0.0-beta4”,或者我是否正在慢慢发疯。也许有人知道如何解决此问题。也许要归功于Beta版的实现。任何帮助将不胜感激。

<androidx.constraintlayout.widget.ConstraintLayout
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_tilemap"
android:layout_width="match_parent"
android:layout_height="wrap_content">


    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintHeight_default="wrap"
        app:layout_constraintHeight_max="280dp"
        app:layout_constrainedHeight="true"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:fadingEdge="horizontal"
        android:fadingEdgeLength="30dp"
        android:fillViewport="true"
        android:requiresFadingEdge="vertical"
        android:id="@+id/rv_comms"
        android:padding="0dp"
        android:clipToPadding="false" />


</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

android android-recyclerview android-constraintlayout
1个回答
0
投票

我刚刚找到了可疑的代码。原来是我适配器上的录音按钮惹的祸。他们包括以下使按钮溢出其他适配器项视图的方法(当按下按钮时,它将像在whatsapp中一样增长,请参见下面的图像)

public void setClip(View v) {
    if (v.getParent() == null) {
        return;
    }

    if (v instanceof ViewGroup) {
        ((ViewGroup) v).setClipChildren(false);
        ((ViewGroup) v).setClipToPadding(false);
    }

    if (v.getParent() instanceof View) {//this part is to blame
        setClip((View) v.getParent());
    }
}

该方法的递归性质(在该方法的最后4行中已经看到了注释)对于从记录按钮向上的整个视图层次结构,基本上将clipToPadding和clipChildren设置为false,这会导致怪异的溢出。我最终只为那些与适配器有关的视图手动将clipToPadding和clipChildren设置为false(这使我可以保留很酷的录制按钮溢出动画而不会出现褪色的边缘问题),现在看起来很漂亮(见下文)。 >

this is what I was going for

© www.soinside.com 2019 - 2024. All rights reserved.