Android约束布局ConstraintLayout详解手机开发

<?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="match_parent"> 
 
    <TextView 
        android:id="@+id/text1" 
        android:layout_width="200dp" 
        android:layout_height="wrap_content" 
        android:background="@android:color/holo_red_light" 
        android:text="1" 
        android:textSize="20dp" 
        app:layout_constraintLeft_toLeftOf="parent" /> 
 
    <TextView 
        android:id="@+id/text2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@android:color/holo_blue_light" 
        android:text="2" 
        android:textSize="20dp" 
        app:layout_constraintLeft_toRightOf="@+id/text1" /> 
 
    <TextView 
        android:id="@+id/text3" 
        android:layout_width="200dp" 
        android:layout_height="wrap_content" 
        android:background="@android:color/holo_green_light" 
        android:text="3" 
        android:textSize="20dp" 
        app:layout_constraintTop_toBottomOf="@+id/text1" /> 
 
    <TextView 
        android:id="@+id/text4" 
        android:layout_width="200dp" 
        android:layout_height="wrap_content" 
        android:background="@android:color/holo_orange_light" 
        android:text="4" 
        android:textSize="20dp" 
        app:layout_constraintBottom_toBottomOf="parent" 
        app:layout_constraintLeft_toLeftOf="parent" 
        app:layout_constraintRight_toRightOf="parent" 
        app:layout_constraintTop_toTopOf="parent" /> 
 
    <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@android:color/darker_gray" 
        android:src="@mipmap/ic_launcher" 
        app:layout_constraintBottom_toTopOf="@id/text4" 
        app:layout_constraintLeft_toRightOf="@id/text2" /> 
</android.support.constraint.ConstraintLayout>

运行结果:

Android约束布局ConstraintLayout详解手机开发

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/3121.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论