Android Cardview中的ConstraintLayout添加空白

Android Cardview中的ConstraintLayout添加空白,android,xml,android-layout,android-cardview,android-constraintlayout,Android,Xml,Android Layout,Android Cardview,Android Constraintlayout,我正在尝试创建一个cardwiew,它有一个ConstraintLayout来组织一些TextView 有时它会按预期显示,但有时会添加额外的空白,例如当键盘关闭时,会破坏布局。我在下面有一个GIF显示CardView在同一时间段内工作和不工作 下面是相关CardView的代码片段。我使用wrap\u content尝试将cardwiew保持在我想要的大小,但它仍然会扩展 <android.support.v7.widget.CardView android:id="@+

我正在尝试创建一个
cardwiew
,它有一个
ConstraintLayout
来组织一些
TextView

有时它会按预期显示,但有时会添加额外的空白,例如当键盘关闭时,会破坏布局。我在下面有一个GIF显示
CardView
在同一时间段内工作和不工作

下面是相关
CardView
的代码片段。我使用
wrap\u content
尝试将
cardwiew
保持在我想要的大小,但它仍然会扩展

    <android.support.v7.widget.CardView
    android:id="@+id/cardView_game_cash"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_margin="6dp"
    app:cardCornerRadius="4dp"
    app:contentPadding="6dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/textView_game_cashLabel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Total Cash"
            app:layout_constraintLeft_toLeftOf="@+id/textView_game_cash"
            app:layout_constraintRight_toRightOf="@+id/textView_game_cash"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView_game_totalProfitLabel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Total Profit"
            app:layout_constraintLeft_toLeftOf="@+id/textView_game_totalProfit"
            app:layout_constraintRight_toRightOf="@+id/textView_game_totalProfit"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView_game_profitLabel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Win Profit"
            app:layout_constraintLeft_toLeftOf="@+id/textView_game_profit"
            app:layout_constraintRight_toRightOf="@+id/textView_game_profit"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView_game_cash"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:gravity="center"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@+id/textView_game_totalProfit"
            app:layout_constraintTop_toBottomOf="@+id/textView_game_cashLabel"
            tools:text="TextView" />

        <TextView
            android:id="@+id/textView_game_totalProfit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:gravity="center"
            app:layout_constraintLeft_toRightOf="@+id/textView_game_cash"
            app:layout_constraintRight_toLeftOf="@+id/textView_game_profit"
            app:layout_constraintTop_toTopOf="@+id/textView_game_cash"
            tools:text="TextView" />

        <TextView
            android:id="@+id/textView_game_profit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:gravity="center"
            app:layout_constraintLeft_toRightOf="@+id/textView_game_totalProfit"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="@+id/textView_game_cash"
            tools:text="TextView" />
    </android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>

我找到了解决问题的方法。在
约束列表中的
文本视图中,我替换了
android:layout\u height=“wrap\u content”

与:

android:layout\u height=“0dp”
app:layout\u constraintHeight\u default=“wrap”


布局按照预期工作,对所有
TextView
进行了更改。

添加内部清单活动标签:android:configChanges=“touchscreen | keyboardHidden | orientation | screenLayout | screenSize | navigation”我添加了这些标志。它仍然无法按预期工作。请在alertdialog中创建edittext,如:我找到了解决方案。我没有在
文本视图中使用
wrap\u内容
,而是使用了
android:layout\u height=“0dp”
以及
app:layout\u constraintHeight\u default=“wrap”
欢迎随时乐于帮助app:layou constraintHeight\u default=“wrap”被删除。现在,您只需将app:layout\u constrained height=“true”添加到每个使用wrap\u内容高度的视图中即可