ConstraintLayout下控件基于另一控件某边居中


如上图,【好的,我知道了】按钮需要基于白色框框底部居中,可以这样实现:

1.两个控件是在ConstraintLayout下的同层级对象。 A,B控件
2.【好的,我知道了】B控件的
layout_constraintBottom_toBottomOf 以及 layout_constraintTop_toBottomOf
都设置成A对象,即可实现。
既 【好的,我知道了】B控件都Top和Bottom都相对A控件底部对齐
重点:【好的,我知道了】需要指定控件高度或者最小高度

<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp">

        <LinearLayout
            android:id="@+id/guardian_share_complete_layout"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_marginTop="135dp"
            android:background="@drawable/button_round_white"
            android:orientation="vertical"
            android:paddingBottom="30dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guardian_share_complete_iv_1">
        </LinearLayout>


 
        <TextView
            android:id="@+id/guardian_share_complete_ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:background="@drawable/shs_button"
            android:gravity="center"
            android:text="好的,知道了"
            android:textColor="@android:color/white"
            android:textSize="15sp"
            app:layout_constraintBottom_toBottomOf="@+id/guardian_share_complete_layout"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/guardian_share_complete_layout" />
    </android.support.constraint.ConstraintLayout>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。