首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >约束布局中的图像行

约束布局中的图像行
EN

Stack Overflow用户
提问于 2017-06-04 15:36:33
回答 2查看 576关注 0票数 0

使用ConstraintLayout中的约束,我创建了一个布局,如下所示:

代码语言:javascript
复制
<?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.进行调整时,我如何克服这种情况?

EN

Stack Overflow用户

发布于 2017-06-04 16:55:38

wrap_content仅要求小部件测量自身,但不会根据最终约束限制其扩展

将以下属性添加到您的ImageView中,当parent constraint layout设置为wrap_content时使用该属性,则会出现高度测量问题,因此可以克服

代码语言:javascript
复制
app:layout_constraintHeight_default="wrap"

并将ImageView height设置为0dp

代码语言:javascript
复制
 <ImageView
            android:id="@+id/post_photo"
            android:layout_width="0dp"
            app:layout_constraintHeight_default="wrap"
            android:layout_height="0dp"
            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"
            />

对于信息,我们可以在宽度问题中使用相同的方法,只需将width替换为0dp并使用以下属性

代码语言:javascript
复制
app:layout_constraintWidth_default="wrap"
票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44351817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档