效果图
实现代码
这个是内容呢显示相对
<?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">
<TextView
android: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"/>
<TextView
android: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>
权重显示如下
把2者的宽度设置为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">
<TextView
android: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"/>
<TextView
android: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>
其效果图