Android开发Android开发经验谈

ConstraintLayout 简单实用

2018-12-06  本文已影响5人  NullPoint3Exce

ConstraintLayout(约束布局)是在2016的Google I/O大会上发布的。

image.png
<?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">

    <!--layout_constraintXX_toYYOf  xx 代表当前组件 YY代表对方组件  -->
    <!--layout_constraintDimensionRatio  比列 -->
    <!-- android:layout_width="0dp"   当文本信息过长的时候,文本信息会覆盖图片组件,设置为0dp
    就可以解决了 -->
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.03"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_launcher_background" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginStart="16dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/imageView"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="HELLO___))))))))))))))))))))))))))))) )))666))" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginStart="16dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/imageView"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        tools:text="XXXXXXXYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYX" />
</android.support.constraint.ConstraintLayout>

注意: 提出一个问题,如果我想让第二行的文本信息和图片底部对齐怎么实现呢?欢迎大家回复我。

上一篇 下一篇

猜你喜欢

热点阅读