[英]ConstraintLayout in Cardview adding white space
I am trying to create a CardView
that has a ConstraintLayout
to organize some TextView
. 我正在尝试创建一个具有
ConstraintLayout
的CardView
来组织一些TextView
。
Sometimes it'll display as intended, but sometimes, it'll add extra white space such as when a keyboard is closed and ruin the layout. 有时它会按预期显示,但有时会增加额外的空白区域,例如键盘关闭时会破坏布局。 I have a GIF below showing the
CardView
working and not working in the same span of time. 我有一个GIF,显示
CardView
正在工作,并且在相同的时间内没有工作。
A code snippet for the relevant CardView
is below. 下面是相关
CardView
代码片段。 I use wrap_content
to try to keep the CardView
at the size I want, but it still expands. 我使用
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>
I found a solution to my problem. 我找到了解决问题的方法。 In the
TextView
within the ConstraintLayout
, I replaced android:layout_height="wrap_content"
在
ConstraintLayout
的TextView
中,我替换了android:layout_height="wrap_content"
with: 有:
android:layout_height="0dp" app:layout_constraintHeight_default="wrap"
The layout worked as intended with that change to all the TextView
within. 布局按预期工作,对所有
TextView
进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.