0

I am using androidx.coordinatorlayout.widget.CoordinatorLayout in my HomeActivity.xml file where I have used the <include> layout="@layout/layout_top_tabs"> tag which is placing the layout at the (0,0) position of the screen (top left corner) which is not what I want. I have used <merge> tags inside layout_top_tabs.xml file. When I remove the <merge> tag, the <include> tag works just fine. I don't know where I am going wrong. Please help!

activity_home.xml file:

<?xml version="1.0" encoding="utf-8"?>

<androidx.coordinatorlayout.widget.CoordinatorLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"  
    tools:context=".HomeActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- Top Toolbar-->

        <RelativeLayout
            android:id="@+id/relLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include layout="@layout/layout_top_tabs" />

        </RelativeLayout>

    </RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

layout_top_tabs.xml file:

<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout

        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true">

        <com.google.android.material.appbar.AppBarLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.appcompat.widget.Toolbar

                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </androidx.appcompat.widget.Toolbar>

        </com.google.android.material.appbar.AppBarLayout>

    </RelativeLayout>

</merge>

I am not getting any error message, but the layouts are not appearing as I have defined them in the xml files.

abhi_47
  • 25
  • 6
  • Please Help Someone, I'm stuck at this point and my assignment is not moving forward – abhi_47 Oct 16 '19 at 16:42
  • What do you really want to do? – Md. Asaduzzaman Oct 16 '19 at 16:47
  • This asnser explains the merge tag: https://stackoverflow.com/a/20874215/8301375 – Traendy Oct 16 '19 at 17:28
  • @Md.Asaduzzaman I want to include layout_top_tabs.xml into activity_home.xml file using the `` tag. But when I try to do so, the layout gets included in activity_home.xml file but at the top left corner of the screen with 0 width and 0 height. I am not able to understand the problem. – abhi_47 Oct 17 '19 at 04:28

0 Answers0