我有一个ConstraintLayout
,只包装了部分内容,我不明白为什么。
下面是我的情况的图形表示:
我希望我的mainConstraintLayout
包装所有东西。如果将layout_height
中的mainConstraintLayout
从wrap_content
更改为match_parent
,我会收到以下警告,但它仍然不起作用:
ScrollView大小验证: 此androidx.constraintlayout.widget.ConstraintLayout应使用android:layout_height =“ wrap_content”。 ScrollView子级必须在滚动维度中将其layout_width或layout_height属性设置为wrap_content而不是fill_parent或match_parent问题ID:ScrollViewSize
有人可以帮助我吗?预先感谢。
更新:xml
<?xml version="1.0" encoding="utf-8"?>
<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"
android:id="@+id/mainView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:backgroundTint="@android:color/white"
tools:context=".activities.EventActivity">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mainConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/eventMainPicture"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginBottom="10dp"
android:contentDescription="@string/event_image_content_description"
android:scaleType="fitXY"
app:layout_constraintBottom_toTopOf="@+id/eventHeaderWrapper"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/event_placeholder_image" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/eventActionWrapper"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventHeaderWrapper">
<Button
android:id="@+id/willPartecipateButton"
style="@android:style/Widget.Material.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/primaryBlue"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="@string/event_will_partecipate"
android:textColor="@color/primaryOrange"
android:textColorHighlight="@color/primaryOrange"
android:textColorHint="@color/primaryOrange"
android:textColorLink="@color/primaryOrange"
android:textSize="14sp"
app:layout_constraintEnd_toStartOf="@+id/interestedButton"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/interestedButton"
style="@android:style/Widget.Material.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/primaryOrange"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="@string/event_interested"
android:textColor="@color/primaryBlue"
android:textColorHighlight="@color/primaryOrange"
android:textColorHint="@color/primaryBlue"
android:textColorLink="@color/primaryBlue"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/willPartecipateButton"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/eventHeaderWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventMainPicture">
<TextView
android:id="@+id/eventCreatedBy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/event_createad_by"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventNamePlaceholder" />
<TextView
android:id="@+id/eventCreatorName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:text="@string/event_creator_placeholder"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/eventCreatedBy"
app:layout_constraintTop_toBottomOf="@+id/eventNamePlaceholder" />
<TextView
android:id="@+id/eventNamePlaceholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/event_name_placeholder"
android:textColor="@android:color/black"
android:textColorHighlight="@android:color/black"
android:textColorHint="@android:color/black"
android:textColorLink="@android:color/black"
android:textSize="28sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/eventInfoWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventActionWrapper">
<ImageView
android:id="@+id/eventDateIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/calendar_icon" />
<ImageView
android:id="@+id/eventPositionIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventDateIcon"
app:srcCompat="@drawable/position_icon" />
<TextView
android:id="@+id/eventDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:text="@string/event_date"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="@+id/eventDateIcon"
app:layout_constraintStart_toEndOf="@+id/eventDateIcon"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/eventPosition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="10dp"
android:text="@string/event_place"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="@+id/eventPositionIcon"
app:layout_constraintStart_toEndOf="@+id/eventPositionIcon"
app:layout_constraintTop_toBottomOf="@+id/eventDate" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/eventDescriptionWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventInfoWrapper">
<TextView
android:id="@+id/eventDescriptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/event_description_title"
android:textColor="@android:color/black"
android:textColorHighlight="@android:color/black"
android:textColorHint="@android:color/black"
android:textColorLink="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/eventDescription"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/event_description"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/eventDescriptionTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/participantsWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent">
<TextView
android:id="@+id/participantsT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/event_participants"
android:textColor="@android:color/black"
android:textColorHighlight="@android:color/black"
android:textColorHint="@android:color/black"
android:textColorLink="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<com.github.ybq.android.spinkit.SpinKitView
android:id="@+id/loadingView"
style="@style/SpinKitView.Large.CubeGrid"
android:layout_width="74dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible"
app:SpinKit_Color="@color/primaryOrange"
app:layout_constraintBottom_toBottomOf="@+id/scrollView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/scrollView"
app:layout_constraintTop_toTopOf="@+id/scrollView" />
</androidx.constraintlayout.widget.ConstraintLayout>
答案 0 :(得分:1)
您为constraint
视图设置了错误的participantsWrapper
。您将participantsWrapper
的顶部设置在mainConstraintLayout
的底部。因此,它自然超越了mainConstraintLayout
。尝试
使用
app:layout_constraintTop_toBottomOf="@+id/eventDescriptionWrapper"
代替
app:layout_constraintTop_toBottomOf="parent"
答案 1 :(得分:0)
您无需更改布局的高度即可包含所有内容,只需确保所有视图都是约束布局的直接子代即可。基本上将所需的所有视图放入标签中:<androidx.constraintlayout.widget.ConstraintLayout> ...</androidx.constraintlayout.widget.ConstraintLayout>
您可能还想考虑使该布局扁平化。将Scrollview设置为父布局,并将其设置为match_parent,然后将所有内容放置在单个约束布局中,使其高度达到wrap_content的高度,以免打乱滚动。