在wrap_content ConstraintLayout中是否不遵守gondMargin? [英] goneMargin is not respected in a wrap_content ConstraintLayout?

查看:72
本文介绍了在wrap_content ConstraintLayout中是否不遵守gondMargin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ConstraintLayout,其高度为wrap_content.

我希望它的高度能够根据其子代的高度折叠或扩展.很简单,很普通,对吧?

I want its height to be able to collapse or expanding, according to its Child's height. Simple and common enough, right?

现在,我的布局看起来像这样:
(首先,请忽略底部的异常超大边距.如您所见,边距仅为16dp,但预览呈现出非常大的边距.)

Now I have a layout which looks like this:
(First of all, please ignore the abnormal super large margin at the bottom. As you can see, the margin is just 16dp but the preview renders a very large margin.)

我的问题是,如果大矩形的可见性设置为gone
根据ConstraintLayout的文档,如果我将其goneMarginTop设置为某个值,则即使其可见性为gone,它也会保留该边距.这样我的Request Date在父级的底部会有一些空间.

My problem is, if the big rectangle's visibility is set to gone,
According to the documentation of ConstraintLayout, if I set its goneMarginTop to a certainValue, it will retain that margin even when its visibility is gone. So that my Request Date will have some space to the bottom of parent.

但是,这无法正常工作. Request Date贴在其父级的底部:
(这又是一个残缺的预览.在我的真实应用中,我可以看到完整的请求日期)

However, this does not work as expected. Request Date sticked to the bottom of its parent:
(This is again a broken preview. In my real app, I am able to see a complete Request Date)

我做错了什么吗?这是我完整的代码:

Have I done something wrong? Here is my complete code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/colorBasicGrey"
    android:layout_marginBottom="2dp">

    <View
        android:id="@+id/item_indicator"
        android:layout_width="8dp"
        android:layout_height="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@color/white"
        android:layout_marginTop="24dp"
        android:layout_marginLeft="24dp"/>

    <TextView
        android:id="@+id/group_member_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/group_member_join_group_request"
        app:layout_constraintTop_toBottomOf="@id/item_indicator"
        app:layout_constraintBottom_toTopOf="@id/item_indicator"
        app:layout_constraintLeft_toRightOf="@id/item_indicator"
        android:layout_marginLeft="8dp"
        style="@style/general45"/>

    <TextView
        android:id="@+id/group_member_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/general45"
        android:textAllCaps="true"
        app:layout_constraintBaseline_toBaselineOf="@id/group_member_label"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="180dp"
        tools:text="ABCDEFGHIJK"/>

    <TextView
        android:id="@+id/group_request_date_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/group_member_request_date_label"
        app:layout_constraintTop_toBottomOf="@id/group_member_label"
        app:layout_constraintLeft_toLeftOf="@id/group_member_label"
        android:layout_marginTop="8dp"
        style="@style/general45"/>

    <TextView
        android:id="@+id/group_request_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/general45"
        android:textAllCaps="true"
        app:layout_constraintBaseline_toBaselineOf="@id/group_request_date_label"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="180dp"
        tools:text="28/10/2017"/>

    <LinearLayout
        android:id="@+id/admin_button_container"
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="24dp"
        android:layout_marginRight="24dp"
        android:layout_marginTop="12dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/group_request_date_label"
        app:layout_constraintVertical_bias="0.0"
        app:layout_goneMarginTop="16dp"
        app:layout_goneMarginLeft="24dp"
        app:layout_goneMarginRight="24dp"
        app:layout_goneMarginBottom="0dp"
        android:visibility="gone">

        <!--To simplify the question, I hided elements inside this LinearLayout-->

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

推荐答案

弄清楚了.

goneMargin用于指示到GONE目标的边距,而不是自身为GONE.

goneMargin is used to indicate the margin to a GONE target, instead of itself being GONE.

因此,实际上我应该将goneMargin属性放在Request Date中,而不是大矩形中.

Therefore in fact I should put the goneMargin attributes in the Request Date instead of the large rectangle.

这篇关于在wrap_content ConstraintLayout中是否不遵守gondMargin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆