material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.24k stars 3.05k forks source link

Tabs in TabLayout not filled to parent in HDpi devices. #2019

Closed vimosanan93 closed 2 years ago

vimosanan93 commented 3 years ago

Description: I have a tab in my application at bottom. I am using com.google.android.material.tabs.Tablayout for it. The issues I'm facing is the two tabs getting centred with wrap content. I searched at max, most of the developers suggested set the

TabMaxWidth to 0dp, TabMode to Fixed and TabGravity to Fill.

I tried with this solution. But nothing is working for me. I'm dealing with this minor issues for more than a day.

Expected behavior: Tabs should be filled with the match parent width.

Source code:

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

    <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.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/white"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <include
                android:id="@+id/tool_bar_content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="16dp"
                layout="@layout/view_topic_details_toolbar_content"
                tools:ignore="RtlHardcoded" />

        </androidx.appcompat.widget.Toolbar>

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

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabInlineLabel="false"
        app:tabMode="fixed"
        app:tabMaxWidth="0dp"
        app:tabGravity="fill"
        app:tabBackground="@drawable/tab_background_color_selector2"
        app:tabTextAppearance="@style/TextAppearance.TabItem"
        app:tabTextColor="@color/colorLightGray"
        app:tabSelectedTextColor="@color/colorDarkText" />

</LinearLayout>

Android API version: For all api version, but for only HDpi and MDpi devices.

Material Library version: Materail version : 1.3.0-alpha01 Device: HDpi (Emulator)

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

GrishinSergey commented 3 years ago

Hello, has the same problem with TabLayout.

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways"
            app:navigationIcon="@drawable/ic_back_blue"
            app:title="Screen"/>

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabBackground="@drawable/selector_tab_indicator"
            app:tabIndicatorColor="@color/colorBlue"
            app:tabIndicatorHeight="2dp"
            app:tabSelectedTextColor="@color/colorBlue"
            app:tabMode="auto"
            app:tabTextAppearance="@style/AppTheme.TabLayout.TabTextAppearance"
            app:tabTextColor="@color/colorTypographyGrey" />
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Tried app:tabMode="scrollable", app:tabMode="scrollable" and app:tabGravity="fill"

drchen commented 3 years ago

Can you provide screenshots?

drchen commented 2 years ago

I'll close the issue due to no further info available. Feel free to reopen it if it's still reproducible.

baderkhane commented 2 years ago

I still have the same issue, please see blow the detail. Version implementation 'com.google.android.material:material:1.4.0'

`<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@android:color/transparent"
        android:backgroundTint="@null"
        app:elevation="0dp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/ivBackButton"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_alignTop="@id/tvMoreTitle"
                android:layout_alignBottom="@id/tvMoreTitle"
                android:layout_alignParentStart="true"
                android:layout_marginStart="24dp"
                android:background="@drawable/selector_ripple"
                android:scaleType="centerInside"
                android:src="@drawable/icon_back" />

            <TextView
                android:id="@+id/tvMoreTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:fontFamily="@font/quicksand_bold"
                android:letterSpacing="0.02"
                android:lineSpacingExtra="4.8sp"
                android:text="@string/personal_information_title"
                android:textColor="@android:color/white"
                android:textSize="19.2sp" />

        </RelativeLayout>

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

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayoutPaymentsDetails"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/gray_dark_common_background"
        android:fontFamily="@font/quicksand_bold"
        android:textSize="12sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/appBar"
        app:tabBackground="@color/gray_dark_common_background"
        app:tabIndicatorColor="@color/red_home_payments"
        app:tabIndicatorGravity="bottom"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabMaxWidth="0dp"
        app:tabSelectedTextColor="@android:color/white"
        app:tabTextAppearance="@style/TabLayoutTheme"
        app:tabTextColor="@color/gray_light_tab_layout_unselected_text" />

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/viewPagerIformations"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintVertical_bias="0.0">
    </androidx.viewpager2.widget.ViewPager2>
</androidx.constraintlayout.widget.ConstraintLayout>

`

TabLayoutMediator( binding.tabLayoutPaymentsDetails, binding.viewPagerIformations ) { tab, position -> tab.text = when (position) { 0 -> getString(R.string.personal_information_contact_tab) 1 -> getString(R.string.personal_information_employment_tab) //Disabling this tab for now 2 -> getString(R.string.myinformation_tab_events) else -> "" } }.attach()