等于 Space 从左、右和中心在两个视图之间 android

Equal Space From left , right and center between two views android

大家好,请帮帮我。我想要两个文本之间的左侧、右侧和中心相等 space view.Below 是我想要的视图图像。

两个文本视图宽度可能会根据文本在 运行 时增加和减少。

使用这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    xmlns:android="http://schemas.android.com/apk/res/android">

<View
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

<View
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>


</LinearLayout>

使用中心重心的重量。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_weight="1"
    android:layout_width="0dp"
    android:text="some text1"
    android:gravity="center"
    android:layout_height="wrap_content" />
<TextView
    android:layout_weight="1"
    android:layout_width="0dp"
    android:text="some text2"
    android:gravity="center"
    android:layout_height="wrap_content" />
</LinearLayout>

使用水平居中约束的约束布局

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


    <Button
        android:id="@+id/button"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="8dp"
        android:text="save"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/button2"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="exit"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/button" />
</android.support.constraint.ConstraintLayout>