实现高度自适应父类但宽高要始终相等

效果图如下,现在各种牌子、各种型号的android很多很多,宽高不能由UI写死,要自适应各种手机,就要使用ConstraintLayout布局界面

注:ConstraintLayout绘制布局太方便了

 

 

重点:app:layout_constraintDimensionRatio="h,1:1"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:background="@color/white">

    <TextView
        android:id="@+id/tv_item_msInsteadSign_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/spacing_12"
        android:layout_marginTop="@dimen/spacing_10"
        android:text="A:距离上边10dp,左边12dp"
        android:textColor="@color/black"
        android:textSize="@dimen/font_12"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_item_msInsteadSign_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/spacing_10"
        android:paddingBottom="@dimen/spacing_10"
        android:text="B:左边跟A一样,在A的下面"
        android:textColor="@color/black"
        android:textSize="@dimen/font_12"
        app:layout_constraintLeft_toLeftOf="@id/tv_item_msInsteadSign_name"
        app:layout_constraintTop_toBottomOf="@id/tv_item_msInsteadSign_name" />

    <TextView
        android:layout_width="@dimen/spacing_0"
        android:layout_height="0dp"
        android:background="@color/text_language"
        android:gravity="center"
        android:text="C:在右边,宽高=Parent高"
        android:textColor="@color/white"
        android:textSize="@dimen/font_12"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="h,1:1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值