ScrollView在RecyclerView.ViewHolder中的不当行为

时间:2019-05-27 09:21:39

标签: android xml android-layout scrollview android-nestedscrollview

我在ViewHolders中具有可扩展的ScrollViews,不再成为“ ScrollViews”,因为我将堆栈跟踪信息(很长的文本)放在ScrollViews中,所以占用了很多垂直空间。使用maxHeight属性根本没有帮助。

添加android:nestedScrollingEnabled="false"确实有帮助。它允许ScrollView跟随maxHeight。但是,ScrollViews无法再滚动。使用扩展ScrollView的自定义视图可以完成相同的操作。没有滚动,但遵循maxHeight

跟随

maxHeight,但是ScrollView不在顶部滚动;底部的正确行为(加上ScrollView应该做的垂直滚动) https://imgur.com/UJwGePT

活动(已修剪):

...
<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="32dp"
            android:layout_marginLeft="32dp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="32dp"
            android:layout_marginRight="32dp"
            android:text="Error Logs"
            android:textAppearance="@style/Text.Header.Big"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="32dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/title" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
...

ViewHolder(已修剪):

...
<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/collapsible"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:maxHeight="384dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/arrow" >

    <HorizontalScrollView
        android:id="@+id/scroll"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:background="#EEE"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" >

        <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:nestedScrollingEnabled="false"
            tools:targetApi="lollipop">

             <TextView
                 android:id="@+id/payload"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_margin="8dp"
                 android:fontFamily="serif-monospace" />
         </ScrollView>
    </HorizontalScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
...

我怀疑这与NestedScrollView有关,但是我不确定原因或地点。

注意:ViewHolder是可展开和折叠的视图,因此请忽略android:visibility="gone"标签

0 个答案:

没有答案