ConstraintLayout 实现水平方向 权重 效果
生活随笔
收集整理的這篇文章主要介紹了
ConstraintLayout 实现水平方向 权重 效果
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
效果圖
?
實(shí)現(xiàn)代碼
? 這個(gè)是內(nèi)容呢顯示相對(duì)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/cons"><TextViewandroid:id="@+id/txt"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="我是小牧"android:layout_marginTop="200dp"app:layout_constraintTop_toTopOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toLeftOf="@+id/txt1"/><TextViewandroid:id="@+id/txt1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="我是小牧"android:layout_marginTop="200dp"app:layout_constraintTop_toTopOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintLeft_toRightOf="@+id/txt"/></android.support.constraint.ConstraintLayout>
權(quán)重顯示如下
?把2者的寬度設(shè)置為0dp 然后添加widght
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/cons"><TextViewandroid:id="@+id/txt"android:layout_width="0dp"android:layout_height="wrap_content"android:text="我是小牧"android:layout_marginTop="200dp"android:gravity="center"app:layout_constraintHorizontal_weight="1"app:layout_constraintTop_toTopOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toLeftOf="@+id/txt1"/><TextViewandroid:id="@+id/txt1"android:layout_width="0dp"android:layout_height="wrap_content"android:text="我是小牧"android:layout_marginTop="200dp"android:gravity="center"app:layout_constraintHorizontal_weight="1"app:layout_constraintTop_toTopOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintLeft_toRightOf="@+id/txt"/></android.support.constraint.ConstraintLayout>
其效果圖
?
總結(jié)
以上是生活随笔為你收集整理的ConstraintLayout 实现水平方向 权重 效果的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 春风作品是谁画的呢?
- 下一篇: 酸菜炖粉条怎么做好吃,猪肉酸菜炖粉条的家