【发布时间】:2017-11-05 05:11:15
【问题描述】:
在ConstraintLayout 中使用约束,我创建了如下布局:
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="2dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
>
<ImageView
android:id="@+id/post_photo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_photo"
/>
<ImageButton
android:id="@+id/create_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@+id/post_photo"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/share_button"
app:srcCompat="@drawable/ic_action_share"
android:scaleType="fitCenter"
/>
<ImageButton
android:id="@+id/share_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@+id/post_photo"
app:layout_constraintLeft_toRightOf="@+id/create_button"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/ic_action_share"
android:scaleType="fitCenter"
/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
我的问题是,只要ImageView 中图像的高度大于其宽度,就不会显示较低的ImageButtons。如果我们在ConstraintLayout 上硬编码一个高度(某种足够的),那么按钮可以根据ImageView 的高度获得一些高度。我相信问题是当View Bounds 调整为ImageView. 我该如何克服这种情况?
【问题讨论】:
标签: android imageview android-constraintlayout