Равное пространство слева, справа и в центре между двумя видами Android - PullRequest
0 голосов
/ 01 декабря 2018

Эй, ребята, пожалуйста, помогите мне.Я хочу равное пространство слева, справа и по центру между двумя текстовыми представлениями. Ниже приведено изображение нужного мне вида. enter image description here

Ширина обоих видов текста может быть увеличена, иуменьшение во время выполнения согласно тексту.

Ответы [ 3 ]

0 голосов
/ 01 декабря 2018

Используйте вес с центром тяжести.

<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>
0 голосов
/ 01 декабря 2018

Использовать макет ограничения с центральным горизонтальным ограничением

<?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>
0 голосов
/ 01 декабря 2018

Используйте это

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