【问题标题】:ConstraintLayout inside a Scrollview - Problem滚动视图内的 ConstraintLayout - 问题
【发布时间】:2021-07-12 22:03:44
【问题描述】:

我一直在尝试弄清楚,当我尝试在滚动视图中移动视图时,它会到处乱跑。

这里是 xml 代码和视频,其行为可以更好地说明它,基本上我无法添加更多视图,因为它到处都是,而且它不断延长我的回收视图并弄乱视图。

我希望能够在片段视图之外添加两个以上的回收站视图。

Link to the video

<ScrollView 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="match_parent"
    android:fillViewport="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:background="#1C212F"
        android:clickable="true"
        android:focusable="true"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        tools:context=".ui.home.HomeMovieFragment">

        <TextView
            android:fontFamily="@font/alfa_slab_one"
            android:id="@+id/tvHomeTitle"
            android:layout_height="wrap_content"
            android:layout_marginStart="32dp"
            android:layout_marginTop="8dp"
            android:layout_width="wrap_content"
            android:text="@string/explore"
            android:textColor="@color/white"
            android:textSize="22sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:fontFamily="@font/cutive"
            android:id="@+id/tvHomeName"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_width="wrap_content"
            android:text="@string/welcome_back"
            android:textColor="@color/white"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/tvHomeTitle"
            app:layout_constraintTop_toBottomOf="@+id/tvHomeTitle" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline2"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.13" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline3"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.62" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvMoviesHome"
            android:layout_height="w"
            android:layout_width="0dp"
            app:layout_constraintBottom_toTopOf="@+id/guideline3"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline2" />

        <TextView
            android:fontFamily="@font/alfa_slab_one"
            android:id="@+id/textView4"
            android:layout_height="wrap_content"
            android:layout_marginStart="24dp"
            android:layout_marginTop="8dp"
            android:layout_width="wrap_content"
            android:text="@string/top_rated"
            android:textColor="@color/white"
            android:textSize="14sp"
            app:layout_constraintBottom_toTopOf="@+id/guideline6"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline3" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_height="40dp"
            android:layout_marginEnd="16dp"
            android:layout_width="40dp"
            android:src="@drawable/temp_image"
            app:layout_constraintBottom_toBottomOf="@+id/btnLogout"
            app:layout_constraintEnd_toStartOf="@+id/btnLogout"
            app:layout_constraintTop_toTopOf="@+id/btnLogout" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline6"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.69" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.93" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvTopRated"
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_constraintBottom_toTopOf="@+id/guideline7"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline6" />

        <ImageButton
            android:background="@null"
            android:foreground="?android:attr/selectableItemBackground"
            android:id="@+id/btnLogout"
            android:layout_height="40dp"
            android:layout_marginEnd="8dp"
            android:layout_marginTop="16dp"
            android:layout_width="40dp"
            android:scaleType="centerCrop"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/icon_logout" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

提前谢谢你。

【问题讨论】:

  • 有人吗?有什么想法吗?
  • 不确定这是否有帮助,但rvMoviesHome RecyclerView 的高度值无效。您的视频中的 IDE 中似乎也突出显示了此错误
  • @PawelLaskowski 什么错误?好像没找到
  • XML文件滚动条旁边的颜色,那里有一个红色的指示符。
  • @PawelLaskowski ,我摆脱了那个错误,但问题仍然存在。可能是因为我试图在 ScrollView 中使用 RecycleView 吗?

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


【解决方案1】:

终于找到了一个解决方案,当我删除它们时,这些指导方针是罪魁祸首,一切都开始按预期工作,我还将 RecycleViews 的高度更改为 wrap_content。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-08
    • 1970-01-01
    • 2017-02-03
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多