【发布时间】:2019-11-17 01:10:42
【问题描述】:
我有一个包含三个矩形 CardView 的活动。我已经设置了尺寸约束,以便它们根据屏幕分辨率而变化。 Please view my constraints here.
The problem is that the CardViews are not changing their size proportionally. 例如,当我在 Nexus 5 (1080 x 1920) 上运行我的应用程序时,底部组件被切成两半,就像我在 Pixel(也是 1080 x 1920),底部组件是所需的大小。
虽然我会尽量使帖子尽可能清晰,但图片肯定有助于理解我面临的问题,所以请查看它们。
..
当屏幕尺寸非常相似时,为什么底部组件会发生如此剧烈的变化?如何修改组件以使它们成为这些不同屏幕尺寸的所需尺寸?
我知道您可以创建 small、normal、large 和 xlarge 布局,我也有,但我认为这不是问题所在。
3 CardViews 的代码:
左上角
<android.support.v7.widget.CardView
android:id="@+id/capture_receipt_cardview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/margin_width_normal"
android:layout_marginEnd="@dimen/button_gap_normal"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toBottomOf="@+id/create_invoice_cardview"
app:layout_constraintEnd_toStartOf="@+id/create_invoice_cardview"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/create_invoice_cardview">
</android.support.v7.widget.CardView>
右上角:
<android.support.v7.widget.CardView
android:id="@+id/create_invoice_cardview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/button_gap_normal"
android:layout_marginTop="185dp"
android:layout_marginEnd="@dimen/margin_width_normal"
android:layout_marginBottom="@dimen/button_gap_normal"
app:layout_constraintBottom_toTopOf="@+id/add_single_cardview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/capture_receipt_cardview"
app:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.CardView>
底部水平:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/add_single_cardview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="400dp"
android:layout_marginBottom="68dp"
app:layout_constraintBottom_toTopOf="@+id/navigation"
app:layout_constraintEnd_toEndOf="@+id/create_invoice_cardview"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/capture_receipt_cardview"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:layout_constraintVertical_weight="0">
</android.support.v7.widget.CardView>
【问题讨论】: