当前位置: 首页 > 知识库问答 >
问题:

ScrollView在约束布局中不工作

姜卜霸
2023-03-14
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    >

    <include
        android:id="@+id/other_toolbar_xml"
        layout="@layout/other_toolbar_xml"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/other_toolbar_xml"
        android:fillViewport="true"
        tools:ignore="MissingConstraints"
        >

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

            <ImageView
                android:id="@+id/img_content_xml"
                android:layout_width="match_parent"
                android:layout_height="170dp"
                app:layout_constraintTop_toBottomOf="@id/other_toolbar_xml"
                android:scaleType="fitXY"
                tools:ignore="NotSibling"
                />

            <TextView
                android:id="@+id/title_content_xml"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/img_content_xml"
                android:layout_marginRight="16dp"
                android:paddingLeft="16dp"
                android:textDirection="rtl"
                android:text="title"
                android:textSize="17sp"
                android:textColor="#1d1d1d"
                />

            <TextView
                android:id="@+id/content_content_xml"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/title_content_xml"
                android:layout_marginTop="20dp"
                android:layout_marginRight="16dp"
                android:layout_marginEnd="16dp"
                android:paddingLeft="16dp"
                android:textDirection="rtl"
                android:text="content"
                android:textColor="#1d1d1d"
                />

            <ImageView
                android:id="@+id/img_date_content_Xml"
                android:layout_width="18dp"
                android:layout_height="18dp"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/content_content_xml"
                android:layout_marginTop="20dp"
                android:layout_marginRight="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="16dp"
                android:src="@drawable/date"
                />

            <TextView
                android:id="@+id/date_content_xml"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toBottomOf="@id/content_content_xml"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintRight_toLeftOf="@id/img_date_content_Xml"
                android:layout_marginTop="20dp"
                android:layout_marginRight="8dp"
                android:layout_marginEnd="8dp"
                android:text="date"
                android:textColor="#1d1d1d"
                android:layout_marginBottom="16dp"
                />

            <TextView
                android:id="@+id/subject_content_xml"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toBottomOf="@id/content_content_xml"
                app:layout_constraintLeft_toLeftOf="parent"
                android:layout_marginTop="20dp"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:singleLine="true"
                android:text="subject"
                android:textColor="#1d1d1d"
                />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

共有1个答案

怀经赋
2023-03-14

由于在 标记中添加tools:ignore=“missingconstraints”,因此错过了一些要给出的约束。

有两种方式:

>

  • 删除父约束布局,只在两个布局中使用RelationveLayout,因为不需要ConstraintLayout。(多用于复杂视图,以方便查看)

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:fillViewport="true"        
        app:layout_constraintTop_toBottomOf="@id/other_toolbar_xml"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" >
    
    //....
    
    </ScrollView>
    

  •  类似资料:
    • 我有两个组件和。每个组件都是由<code>ConstraintLayout</code>创建的。现在,我从上面的组件创建<code>WelcomeScreen</code>。 用例1:使用静态< code>ConstraintLayout(在< code>ConstraintLayout内的< code>ConstraintLayout) 结果:布局预览不显示任何内容 用例2:<代码>Welcom

    • 我刚开始使用约束布局,我在编译设计文件时遇到断言错误,这个问题就会单独出现。解决此问题的正确方法是什么?我搞砸了洞日。这是我的XML设计。 和我的错误日志: java.lang.AssertionError:在Android.Support.Constraint.Solver.Widgets.Guideline.GetAnchor(Guideline.java:159)在Android.Suppo

    • 我是android编程的新手,我还不知道很多事情。我在这里试图实现的是这样的东西。如果用户没有互联网连接,广告不会显示,或者如果广告由于某种原因没有加载,那么广告不会显示。但布局保持不变,这意味着广告空间是空的。我所做的是在一个相对的布局内扭曲广告视图,然后创建了一个函数,检查广告是否被加载,然后改变布局的可见性,这似乎工作,并解决了当广告不加载时的空白问题。但我认为这不是最好的方法,必须有更好的

    • 我的约束布局的版本是。在我的布局中包含了一个工具栏之后,工具栏的左右两边都有空间,如下图所示 这是我的工具栏的代码 我以以下方式将其包含在我的布局中 我没有在布局文件的根元素中使用任何附加的填充或边距。 另一个奇怪的事情是,如果我编译或构建程序,我的代码会自动改变,比如 更改为

    • 我试图填充一个相对的布局与4卡视图在它。每个cardview由一个图像和一个文本视图组成。我将所有卡片视图包装在一个相对布局中,将相对布局包装在一个滚动视图中。不管用。如果我移除scrollview,它可以正常工作。尝试将scrollview放入相对布局中。但没有工作代码:

    • 我是AutoLayout的新手。我已经知道很多关于这个autoLayout的问题和教程,但是我还没有找到我的解决方案。所以提前感谢您的任何帮助。 我的要求是什么? 我必须制作UIView,它将在按下屏幕底部带有动画的按钮后出现在屏幕上。(如键盘)。我使用autoLayout在xib文件中创建了此UIView。到目前为止,我已经这样做了。 在ViewDidLoad中: 在这个视图中,它包含(滚动视图