IT虾米网

Android约束布局ConstraintLayout

mate10pro 2018年05月31日 手机开发 1197 0

<?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>


运行结果:


评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!