gpt4 book ai didi

android - Cardview 中的 ConstraintLayout 添加空白

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:11 24 4
gpt4 key购买 nike

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

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

ConstraintLayout adding white space

相关 CardView 的代码 fragment 如下。我使用 wrap_content 尝试将 CardView 保持在我想要的大小,但它仍然会扩展。

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

最佳答案

我找到了解决问题的方法。在 ConstraintLayout 内的 TextView 中,我替换了 android:layout_height="wrap_content"

与:

android:layout_height="0dp"
应用程序:layout_constraintHeight_default="wrap"

随着对所有 TextView 的更改,布局按预期工作。

关于android - Cardview 中的 ConstraintLayout 添加空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43126724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com