首页 > 解决方案 > 如何在滚动时修复 ConstraintLayout 中的视图?

问题描述

我有一个layout可滚动的。我需要ImageView在父级的右下角放置一个ImageView位置,即使在滚动时也应该固定到该位置。下面是我写的代码。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/random_text"
        android:textSize="20dp"
        app:layout_constraintRight_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/back_to_top"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/back_to_top"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

</android.support.constraint.ConstraintLayout>

但是它ImageView可以随着内容滚动而不是固定的。如何实现这一点ConstraintLayout?一种解决方案是将其放在ImageView外部ConstraintLayout,但将其放在内部时是否有任何地方可以实现它ConstraintLayout

注意:这是一个非常简单的布局,是我为发布问题而编造的。真正的布局更复杂,但也有同样的问题。

标签: androidandroid-constraintlayout

解决方案


推荐阅读