floating textView between 2 layout

27 Views Asked by At

I have design like this, I want to float the 2 item in the center like the image, but I'm confused how to do that

enter image description here

I have tried like this to achieve that design but still got nothing

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:background="@drawable/icon_banner_home">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="20dp"
                android:lineSpacingExtra="8dp"
                android:text="@string/selamat_datang_admin" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center">

            <LinearLayout
                android:id="@+id/dashboard"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginStart="10dp"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginBottom="10dp"
                android:background="@drawable/rounded_corner_menu"
                android:orientation="vertical"
                android:padding="10dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_margin="10dp"
                    android:lineSpacingExtra="2dp"
                    android:text="90%"
                    android:textAlignment="center" />


                <TextView
                    android:layout_width="90dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:lineSpacingExtra="2dp"
                    android:text="Tugas Selesai Hari Ini"
                    android:textAlignment="center" />


            </LinearLayout>

            <LinearLayout
                android:id="@+id/checkin"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_margin="10dp"
                android:layout_toRightOf="@+id/dashboard"
                android:background="@drawable/rounded_corner_menu"
                android:orientation="vertical"
                android:padding="10dp">

                <ImageView
                    android:layout_width="28dp"
                    android:layout_height="33dp"
                    android:layout_gravity="center"
                    android:src="@drawable/icon_green_checklist" />

                <TextView
                    android:layout_width="90dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:lineSpacingExtra="2dp"
                    android:text="Tepat Waktu"
                    android:textAlignment="center" />


            </LinearLayout>


        </RelativeLayout>

        <com.pastiberes.ExpandableHeightGridView
            android:id="@+id/gvMenu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_marginTop="50dp"
            android:columnWidth="100dp"
            android:gravity="center"
            android:isScrollContainer="false"
            android:numColumns="4"
            android:scrollbars="none"
            android:stretchMode="columnWidth"
            android:textAlignment="center" />


    </LinearLayout>


</ScrollView>

I know this is a stupid question, I have search but many of them using floating button. Can you help me please? Thank you for your help

1

There are 1 best solutions below

0
Khush Parmar On

You can use the ConstraintLayout to achieve the same as setting the one parent as ConstraintLayout inside your ScrollView instead of the LinearLayout and then by setting Constraint top of your dashboard linearlayout to bottom of the header and also by setting bottom to bottom of the same.

Below is the example of the same, You can modify this as per your requirement.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:background="@drawable/icon_banner_home"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="20dp"
            android:lineSpacingExtra="8dp"
            android:text="@string/selamat_datang_admin" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="@id/top"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/top"
        android:layout_gravity="center">

        <LinearLayout
            android:id="@+id/dashboard"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginStart="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginBottom="10dp"
            android:background="@drawable/rounded_corner_menu"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="10dp"
                android:lineSpacingExtra="2dp"
                android:text="90%"
                android:textAlignment="center" />


            <TextView
                android:layout_width="90dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:lineSpacingExtra="2dp"
                android:text="Tugas Selesai Hari Ini"
                android:textAlignment="center" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/checkin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_margin="10dp"
            android:layout_toRightOf="@+id/dashboard"
            android:background="@drawable/rounded_corner_menu"
            android:orientation="vertical"
            android:padding="10dp">

            <ImageView
                android:layout_width="28dp"
                android:layout_height="33dp"
                android:layout_gravity="center"
                android:src="@drawable/icon_green_checklist" />

            <TextView
                android:layout_width="90dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:lineSpacingExtra="2dp"
                android:text="Tepat Waktu"
                android:textAlignment="center" />

        </LinearLayout>

    </RelativeLayout>

    <com.pastiberes.ExpandableHeightGridView
        android:id="@+id/gvMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_marginTop="50dp"
        android:columnWidth="100dp"
        android:gravity="center"
        android:isScrollContainer="false"
        android:numColumns="4"
        android:scrollbars="none"
        android:stretchMode="columnWidth"
        android:textAlignment="center" />

</androidx.constraintlayout.widget.ConstraintLayout>