I am currently implementing an TabLayout inside AppBarLayout. Here is an effect I want in my TabLayout:
Before scrolling
After scrolling
Here is layout for the fragment_product_item:
<?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=".ProductItemFragment">
<!-- TODO: Update blank fragment layout -->
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="4dp"
app:layout_scrollFlags="scroll|enterAlways">
<ImageView
android:id="@+id/imgProductItem"
android:layout_width="100dp"
android:layout_height="100dp"
android:contentDescription="@string/img_product_ava_des"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_toEndOf="@id/imgProductItem"
android:orientation="vertical">
<TextView
android:id="@+id/tvProductItemPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/default_text_placeholder"
android:textAppearance="?attr/textAppearanceBody1" />
<TextView
android:id="@+id/tvProductItemSoldQuantities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/default_text_placeholder"
android:textAppearance="?attr/textAppearanceBody1"
android:textColor="#ACA5A5" />
</LinearLayout>
</RelativeLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/productItemTabs"
android:layout_width="match_parent"
android:layout_height="75dp"
android:elevation="5dp"
app:tabPaddingBottom="8dp"
app:tabPaddingTop="8dp" />
</com.google.android.material.appbar.AppBarLayout>
...
Here is the custom layout I used for the TabLayout's item:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgTabIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/tvTabDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_toEndOf="@id/imgTabIcon"
android:text="@string/default_text_placeholder"
android:textAppearance="?attr/textAppearanceBody1" />
<TextView
android:id="@+id/tvTabTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvTabDetail"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/default_text_placeholder"
android:textAppearance="?attr/textAppearanceBody2" />
How can I hide only the tvTabTitle when the scrolling occurs like the images provided? Sorry because I dont have enough reputation for the images to show directly
question from:
https://stackoverflow.com/questions/65952770/scroll-custom-tablayout 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…