ConstraintLayout 水平比例佈局 1:1:2

AndroLi發表於2017-06-21

ConstraintLayout 水平比例佈局 1:1:2

//以下程式碼展示了一個 1:1:2的ConstraintLayout佈局, 關鍵點就是 位置的left,right的擺放,才能出現這個效果。 認真體會

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.okaylens.it8951demo.MainActivity">

    <Button
        android:id="@+id/connect_usb_bt"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintRight_toLeftOf="@id/send_bmp_bt"
        android:layout_width="0dp"
        android:layout_height="100dp"
        />
    <Button
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/send_bmp_bt"
        app:layout_constraintLeft_toRightOf="@id/connect_usb_bt"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintRight_toLeftOf="@id/send_jpg_bt"
        android:layout_width="0dp"
        android:layout_height="100dp"
        />
    <Button
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/send_jpg_bt"
        app:layout_constraintLeft_toRightOf="@id/send_bmp_bt"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_weight="2"
        android:layout_width="0dp"
        android:layout_height="100dp"
        />



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

相關文章