Как центрировать «TextView» во flexbox? - PullRequest
0 голосов
/ 30 сентября 2019

Я пытаюсь центрировать текст в FlexboxLayout. Я использую эту библиотеку com.google.android:flexbox:0.2.5. У меня есть несколько текст в столбце. Я пытаюсь многими способами поместить их в середину этого столбца без успеха.

<com.google.android.flexbox.FlexboxLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            style="?metaButtonBarStyle"
            android:layout_width="77dp"
            android:layout_height="match_parent"
            android:background="@drawable/bg_pattern_dark_bitmap"
            android:orientation="vertical"
            android:alpha="1"
            app:flexWrap="wrap"
            app:justifyContent="space_between"
            >

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="lol"
                />
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="lol"
                />
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="lol"
                />
    </com.google.android.flexbox.FlexboxLayout>

Спасибо за любую помощь

Ответы [ 2 ]

0 голосов
/ 30 сентября 2019

Добавьте эту строку в TextView

 android:gravity="center_vertical"

Для просмотра изображений

поместите просмотр изображений в Linearlayout и установите гравитацию

  <com.google.android.flexbox.FlexboxLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    style="?metaButtonBarStyle"
    android:layout_width="77dp"
    android:layout_height="match_parent"
    android:background="@drawable/bg_pattern_dark_bitmap"
    android:orientation="vertical"
    android:alpha="1"
    app:flexWrap="wrap"
    app:justifyContent="space_between">

<LinearLayout android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="center_vertical">

    <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:background="@color/colorPrimary"/>

</LinearLayout>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="lol"
        android:gravity="center_vertical"/>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="lol"
        android:gravity="center_vertical"/>

</com.google.android.flexbox.FlexboxLayout>
0 голосов
/ 30 сентября 2019

Используйте app:justifyContent="space_evenly" вместо space_between

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...