How to increase tab height in xml without changing position. Also viewpager goes behind tab layout

Tags: , , , ,



Please help me. I have a tab layout and a viewpager. I have 2 problems. I want to decrease the height of tablayout. Also while scrolling(a list view in the page) as the viewpager is behind tab layout , the tab layout hides some elements of the list. Please help me solve the problem!!!

The problem can be resolved but i dont know how. Please hep me soon.I have tried many ways but nothing solved it. Also send the entire corrected code as answer If i just set the layoutheight of the tab layout… this happens… See there is a white line below the bottom grey color tablayout

See there is a white line below the bottom grey color tablayout

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    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"
    android:id="@+id/root">


    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.NoActionBar.AppBarOverlay">


        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/bgColor"

            app:popupTheme="@style/AppTheme.PopupOverlay">
            <!--app:layout_scrollFlags="scroll|snap"-->

            <TextView
                android:id="@+id/tv_selected_chat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:gravity="center_vertical"
                android:text="0"
                android:textColor="@color/colorWhite"
                android:textSize="17sp"
                android:visibility="gone" />

        </androidx.appcompat.widget.Toolbar>


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


    <androidx.viewpager.widget.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="644dp"
        android:paddingBottom="20dp"
        ads:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/activity_main">


    </androidx.viewpager.widget.ViewPager>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/open_new_chat_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="27dp"
        android:layout_marginBottom="84dp"
        android:tint="@color/colorWhite"
        android:visibility="visible"
        app:backgroundTint="@color/colorAccent"
        app:fabSize="normal"
        app:layout_anchor="@id/view_pager"
        app:layout_anchorGravity="bottom|right|end"
        app:srcCompat="@drawable/ic_message" />


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/text_status_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="27dp"
        android:layout_marginBottom="84dp"
        android:tint="@color/colorWhite"
        android:visibility="invisible"
        app:backgroundTint="@color/colorGreen"
        app:fabSize="normal"
        app:layout_anchor="@id/view_pager"
        app:layout_anchorGravity="bottom|right|end"
        app:srcCompat="@drawable/ic_edit" />

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:background="@color/bgColor"
        ads:layout_anchor="@+id/view_pager"
        ads:layout_anchorGravity="bottom|center"
        ads:tabBackground="@color/actionModeBackground"
        ads:tabIndicatorColor="@color/audio_wave_background"
        ads:tabIndicatorHeight="2dp"
        app:tabGravity="fill"
        app:tabMaxWidth="0dp"
        app:tabMode="fixed"
        app:tabSelectedTextColor="@android:color/white" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Answer

you can use hardcode value of height as like 20dp etc as much you require. also move your view pager upside appbar layout and use this code

<androidx.viewpager.widget.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="644dp"
    android:paddingBottom="20dp"
    ads:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"/>


look at your code you dont use this instead of using this

<androidx.viewpager.widget.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="644dp"
    android:paddingBottom="20dp"
    ads:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main">
  
   </androidx.viewpager.widget.ViewPager>

it means you are using this area to add some layout etc.



Source: stackoverflow