我正在尝试创建一个CardView
有一个ConstraintLayout
组织一些TextView
.
有时它会按预期显示,但有时,它会添加额外的空白,例如当键盘关闭时,会破坏布局。我下面有一个 GIF 显示CardView
在同一时间段内工作和不工作。
相关的代码片段CardView
在下面。我用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>
我找到了解决问题的方法。在里面TextView
内ConstraintLayout
,我替换了android:layout_height="wrap_content"
with:
android:layout_height="0dp"
app:layout_constraintHeight_default="wrap"
布局按预期进行,所有更改均已完成TextView
within.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)