【发布时间】:2017-03-28 14:29:55
【问题描述】:
我正在尝试制作一张我选择约束布局的孩子的卡片。虽然我需要将图像视图设置为所有尺寸设备的 1:1 纵横比。我能够成功实现它,但面临图像视图移出屏幕的问题。 请参考下面的链接以轻松理解我的问题。
这是我的卡片视图 xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="4dp"
android:background="@android:color/background_light"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="2dp"
app:cardElevation="2dp"
app:cardUseCompatPadding="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteX="3dp"
tools:layout_editor_absoluteY="4dp">
<ImageView
android:id="@+id/imageView4"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="1dp" //this line creating issue to me
android:scaleType="centerCrop"
app:layout_constraintDimensionRatio="w,1:1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintHorizontal_bias="0.0" />
<TextView
android:id="@+id/textView6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:singleLine="true"
android:text="TextView"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView4"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
android:layout_marginLeft="24dp" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="14sp"
app:layout_constraintLeft_toLeftOf="@+id/textView6"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
android:layout_marginLeft="0dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/textView6" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:text="TextView"
android:textColor="@color/colorAccent"
android:textSize="14sp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/textView7"
app:layout_constraintRight_toRightOf="@+id/textView7"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/textView7" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
【问题讨论】:
-
我认为布局只能这样显示,你需要通过构建布局进行测试以显示更清晰。
-
这是约束布局的缺点还是我错过了任何属性?