Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

android - Tablayout tab icon not showing on real device but on emulator

The problem I encounter is, that my tablayout tab.icons are not showing on my real device (samsung galaxy s7) but everything works fine on the emulator.

Emulator

enter image description here

Real Device

enter image description here

Fragment Tablayout

private fun initImageView() {
    shopItemBinding.productImageViewpager.adapter = shopItemImageViewPager.apply { submitList(productArgs.product.images) }
    
    TabLayoutMediator(shopItemBinding.shopItemTablayout, shopItemBinding.productImageViewpager) { tab, _ ->
            when {
                productArgs.product.images.size > 1 -> tab.icon = ContextCompat.getDrawable(
                    requireContext(),
                    R.drawable.shop_item_tab_unselected // this is the drawable for the dots
                )
                else -> shopItemBinding.shopItemTablayout.visibility = View.GONE // deleting this made no difference
            }
        }.attach()
    }

Layout xml

<androidx.viewpager2.widget.ViewPager2
    android:id="@+id/product_image_viewpager"
    android:layout_width="0dp"
    android:layout_height="142dp"
    android:adjustViewBounds="true"
    android:contentDescription="@null"
    android:fitsSystemWindows="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.tabs.TabLayout
    android:id="@+id/shop_item_tablayout"
    android:layout_width="0dp"
    android:layout_height="16dp"
    android:layout_marginTop="8dp"
    app:layout_constraintEnd_toEndOf="@+id/product_image_viewpager"
    app:layout_constraintStart_toStartOf="@+id/product_image_viewpager"
    app:layout_constraintTop_toBottomOf="@id/product_image_viewpager"
    app:tabIndicator="@null"
    app:tabIndicatorFullWidth="false"
    app:tabIndicatorGravity="top"
    app:tabMaxWidth="16dp" />

It doesn't look the view is GONE because the height of both the emulator and the real device remain the same


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...