0

I want to position a TextView centered horizontally from his parent but I don't want the parent to get the width of this TextView. I also want that TextView to grow outside the parent width if it's bigger than the parent. I want to do like a position: absolute in HTML.

In brief, I want the FlexBox to have the width of the Icon, but I want the TextView to be position absolutely centered under the icon and be sure that the TextView appears on one line.

Android View Screenshot

There is my layout code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_gravity="bottom"
    android:layoutDirection="ltr"
    android:orientation="vertical"
    android:background="@drawable/bg_selector"
    android:id="@+id/player_control_view"
    tools:targetApi="28">

    <com.google.android.flexbox.FlexboxLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:alignItems="flex_end"
        android:padding="20dp"
        >

        <com.google.android.flexbox.FlexboxLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/center"
            app:layout_flexGrow="1"
            app:flexDirection="column"
            >

            <com.google.android.flexbox.FlexboxLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/timeline"
                >

                <TextView
                    android:id="@id/exo_position"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:includeFontPadding="false"
                    android:paddingLeft="4dp"
                    android:paddingRight="4dp"
                    android:textColor="#FFBEBEBE"
                    android:textSize="14sp"
                    app:layout_flexGrow="0"
                    android:textStyle="bold" />

                <View
                    android:id="@id/exo_progress_placeholder"
                    android:layout_width="0dp"
                    android:layout_height="16dp"
                    app:layout_flexGrow="1" />

                <TextView
                    android:id="@id/exo_duration"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:includeFontPadding="false"
                    android:paddingLeft="4dp"
                    android:paddingRight="4dp"
                    android:textColor="#FFBEBEBE"
                    android:textSize="14sp"
                    app:layout_flexGrow="0"
                    android:textStyle="bold" />

            </com.google.android.flexbox.FlexboxLayout>

        </com.google.android.flexbox.FlexboxLayout>

    </com.google.android.flexbox.FlexboxLayout>

    <com.google.android.flexbox.FlexboxLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:justifyContent="center">
        <com.google.android.flexbox.FlexboxLayout
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:id="@+id/buttons1"
            app:justifyContent="center"
            app:flexDirection="column"
            >

            <ImageButton
                android:id="@+id/custom_exo_play1"
                style="@style/ExoMediaButton.Play"
                tools:ignore="ContentDescription" />

            <TextView
                android:id="@+id/resume_text1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="This is a big test for Felix"
                android:breakStrategy="simple"
                android:textColor="@android:color/white"/>


        </com.google.android.flexbox.FlexboxLayout>
    </com.google.android.flexbox.FlexboxLayout>


</LinearLayout>

I don't know how to achieve that. Be aware that in my example, I only have one button, but there will 4-5 buttons side by side.

Thanks!

0 Answers0