为什么我的ConstraintLayout中的ScrollView保持没有高度而不是遵循约束?

我有我的ScrollView在我的片段没有高度的问题。我将视图添加到嵌套在我的ScrollView中的LinearLayout中。 如果我将ScrollView的高度设置为0dp,那么我在LinearLayout中看不到视图。 如果我将ScrollView的高度设置为410dp,那么我会看到视图。 我只是想填满屏幕的底部。为什么我的ConstraintLayout中的ScrollView保持没有高度而不是遵循约束?

我错过了什么?

<?xml version="1.0" encoding="utf-8"?> 

<android.support.constraint.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">

<TextView

android:id="@+id/seriesTitleTextView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:labelFor="@+id/seriesTitleEditBox"

android:text="Series Title"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintTop_toTopOf="parent"/>

<EditText

android:id="@+id/seriesTitleEditBox"

android:layout_width="390dp"

android:layout_height="40dp"

android:imeOptions="actionNext"

android:inputType="textCapWords"

android:selectAllOnFocus="true"

app:layout_constraintLeft_toLeftOf="@+id/seriesTitleTextView"

app:layout_constraintTop_toBottomOf="@+id/seriesTitleTextView"

/>

<TextView

android:id="@+id/tvmdIDTextView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:labelFor="@+id/tvmdIDEditBox"

android:text="TVMD ID"

app:layout_constraintLeft_toLeftOf="@+id/seriesTitleEditBox"

app:layout_constraintTop_toBottomOf="@+id/seriesTitleEditBox"

/>

<EditText

android:id="@+id/tvmdIDEditBox"

android:layout_width="200dp"

android:layout_height="40dp"

android:imeOptions="actionNext"

android:inputType="textCapWords"

android:selectAllOnFocus="true"

app:layout_constraintLeft_toLeftOf="@+id/tvmdIDTextView"

app:layout_constraintTop_toBottomOf="@+id/tvmdIDTextView"

/>

<Switch

android:id="@+id/finishedSwitch"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

app:layout_constraintTop_toBottomOf="@id/tvmdIDTextView"

app:layout_constraintRight_toRightOf="parent"

android:text="Finished? "/>

<TextView

android:id="@+id/detailsHeaderBackgroundTextView"

android:text=" "

android:layout_width="0dp"

android:layout_height="50dp"

android:layout_marginTop="20dp"

android:background="@color/colorPrimary"

app:layout_constraintTop_toBottomOf="@+id/finishedSwitch"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

/>

<TextView

android:id="@+id/detailHeaderTextView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginTop="10dp"

android:background="@color/colorPrimary"

android:text="Season 99"

android:textColor="@android:color/white"

android:textSize="20sp"

app:layout_constraintLeft_toLeftOf="@+id/detailsHeaderBackgroundTextView"

app:layout_constraintTop_toTopOf="@id/detailsHeaderBackgroundTextView"

/>

<ImageButton

android:id="@+id/addViewing"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:background="@color/colorPrimary"

android:contentDescription="Add Button"

android:onClick="addViewingClickHandler"

android:src="@android:drawable/ic_menu_add"

app:layout_constraintRight_toRightOf="@id/detailsHeaderBackgroundTextView"

app:layout_constraintTop_toTopOf="@id/detailsHeaderBackgroundTextView"/>

<ScrollView

android:layout_width="wrap_content"

android:layout_height="0dp"

app:layout_constraintTop_toBottomOf="@+id/detailsHeaderBackgroundTextView"

app:layout_constraintBottom_toBottomOf="parent"

>

<LinearLayout

android:id="@+id/detailsLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

/>

</ScrollView>

</android.support.constraint.ConstraintLayout>

回答:

问题从具有高度设置为WRAP_CONTENT父布局来了,而不是match_parent。

回答:

只要改变你的滚动视图喜欢下面

<?xml version="1.0" encoding="utf-8"?> 

<android.support.constraint.ConstraintLayout

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">

<TextView

android:id="@+id/seriesTitleTextView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:labelFor="@+id/seriesTitleEditBox"

android:text="Series Title"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<EditText

android:id="@+id/seriesTitleEditBox"

android:layout_width="390dp"

android:layout_height="40dp"

android:imeOptions="actionNext"

android:inputType="textCapWords"

android:selectAllOnFocus="true"

app:layout_constraintLeft_toLeftOf="@+id/seriesTitleTextView"

app:layout_constraintTop_toBottomOf="@+id/seriesTitleTextView" />

<TextView

android:id="@+id/tvmdIDTextView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:labelFor="@+id/tvmdIDEditBox"

android:text="TVMD ID"

app:layout_constraintLeft_toLeftOf="@+id/seriesTitleEditBox"

app:layout_constraintTop_toBottomOf="@+id/seriesTitleEditBox" />

<EditText

android:id="@+id/tvmdIDEditBox"

android:layout_width="200dp"

android:layout_height="40dp"

android:imeOptions="actionNext"

android:inputType="textCapWords"

android:selectAllOnFocus="true"

app:layout_constraintLeft_toLeftOf="@+id/tvmdIDTextView"

app:layout_constraintTop_toBottomOf="@+id/tvmdIDTextView" />

<Switch

android:id="@+id/finishedSwitch"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Finished? "

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toBottomOf="@id/tvmdIDTextView" />

<TextView

android:id="@+id/detailsHeaderBackgroundTextView"

android:layout_width="0dp"

android:layout_height="50dp"

android:layout_marginTop="20dp"

android:background="@color/colorPrimary"

android:text=" "

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toBottomOf="@+id/finishedSwitch" />

<TextView

android:id="@+id/detailHeaderTextView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="20dp"

android:layout_marginTop="10dp"

android:background="@color/colorPrimary"

android:text="Season 99"

android:textColor="@android:color/white"

android:textSize="20sp"

app:layout_constraintLeft_toLeftOf="@+id/detailsHeaderBackgroundTextView"

app:layout_constraintTop_toTopOf="@id/detailsHeaderBackgroundTextView" />

<ImageButton

android:id="@+id/addViewing"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:background="@color/colorPrimary"

android:contentDescription="Add Button"

android:onClick="addViewingClickHandler"

android:src="@android:drawable/ic_menu_add"

app:layout_constraintRight_toRightOf="@id/detailsHeaderBackgroundTextView"

app:layout_constraintTop_toTopOf="@id/detailsHeaderBackgroundTextView" />

<ScrollView

android:layout_width="0dp"

android:layout_height="0dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toBottomOf="@+id/detailsHeaderBackgroundTextView">

<LinearLayout

android:id="@+id/detailsLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<!--SAMPLE TEXTVIEW-->

<android.support.v7.widget.AppCompatTextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="hello" />

</LinearLayout>

</ScrollView>

</android.support.constraint.ConstraintLayout>

以上是 为什么我的ConstraintLayout中的ScrollView保持没有高度而不是遵循约束? 的全部内容, 来源链接: utcz.com/qa/260345.html

回到顶部