Android ConstraintLayout 使用实例

本文介绍了一个使用ConstraintLayout的布局示例,详细展示了如何通过各种属性如宽高比、屏幕比例等来实现元素间的精确对齐与定位。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

layout_constraintDimensionRatio 宽高比例
layout_constraintWidth_percent 与屏幕比例

居中  左 右 

app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"

layout_constraintTop_toTopOf 首个

layout_constraintTop_toBottomOf 对应ID下面  左右

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/view_title">


    <LinearLayout
        android:id="@+id/ll_input_ed"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/tv_inpute_top"
        app:layout_constraintDimensionRatio="h,246:40"
        app:layout_constraintWidth_percent="0.656"
        android:layout_marginTop="13dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:background="@drawable/back_input"
        android:orientation="vertical">
        <com.dogness.platform.feeder.widget.CustomEditText
            android:id="@+id/input_ed"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textSize="@dimen/textSmall2"
            android:background="@null"
            android:hint="@string/test"
            android:textCursorDrawable='@null'
            android:cursorVisible="true"
            android:gravity="center" />
    </LinearLayout>
<ImageView
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:id="@+id/imaeview"
    android:layout_marginTop="84dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintDimensionRatio="h,333:383"
    app:layout_constraintWidth_percent="0.361"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/blue_guide"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tv_input_guide"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/imaeview"
    android:textSize="@dimen/textSmall2"
    android:text="@string/test"
    android:textColor="@color/app_dialog_content"
    android:layout_marginTop="38dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_inpute_top"
        android:text="@string/test"
        android:textSize="@dimen/textSmall2"
        android:paddingStart="10dp"
        android:paddingEnd="10dp"
        app:layout_constraintTop_toBottomOf="@id/tv_input_guide"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:textColor="@color/app_text_black"
        android:layout_marginTop="10dp"
        />

<Button
    android:layout_width="0dp"
    android:layout_height="@dimen/pw_bottom_btn_height"
    android:id="@+id/input_bt"
    android:layout_marginLeft="85dp"
    android:layout_marginRight="85dp"
    android:layout_marginTop="64dp"
    app:layout_constraintWidth_percent="0.656"
    app:layout_constraintTop_toBottomOf="@id/ll_input_ed"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:text="@string/test"
    android:gravity="center"
    android:textSize="@dimen/textSmall2"
    android:textColor="@color/app_text_white"
    android:background="@drawable/btnbg_blue_light_angle_selected"
    />
</androidx.constraintlayout.widget.ConstraintLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值