KailuZhang / TabLayoutMediator2

实现TabLayout+RecyclerView的锚点定位
78 stars 18 forks source link

关于底部布局吸底 #1

Closed wohelu666 closed 3 years ago

wohelu666 commented 3 years ago

想问下底部布局始终在底部是用的bottom_sheet_behavior吗?

KailuZhang commented 3 years ago

不是 因为是固定在底部的,所以是在ConstraintLayout布局中直接写的,layout_constraintBottom_toBottomOf设为parent就行了

wohelu666 commented 3 years ago

是不是用的bottom_sheet_behavior?

wohelu666 commented 3 years ago

demo里面没有这个,能否把效果图布局代码发来看看,做一下参考,因为父布局是coordinatorlayout, 不好用constraintlayout.

KailuZhang commented 3 years ago
  <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.scwang.smartrefresh.layout.SmartRefreshLayout
            android:id="@+id/swipe_refresh_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="52dp">

            <com.vv.bodylib.vbody.recyclerview.baseview.VVPullHeaderLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srlAccentColor="#aaa"
                app:srlDrawableMarginRight="-10dp"
                app:srlDrawableProgressSize="25dp" />

            <androidx.coordinatorlayout.widget.CoordinatorLayout
                android:id="@+id/coordinator_layout"
                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:animateLayoutChanges="true"
                    android:background="?attr/colorSurface"
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                    <com.google.android.material.appbar.CollapsingToolbarLayout
                        android:id="@+id/toolbar_layout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:collapsedTitleGravity="center"
                        app:contentScrim="?attr/colorSurface"
                        app:layout_scrollFlags="scroll|exitUntilCollapsed"
                        app:statusBarScrim="?attr/colorSurface"
                        app:titleEnabled="false"
                        app:toolbarId="@id/toolbar">

                        <androidx.viewpager2.widget.ViewPager2
                            android:id="@+id/vp_goods_guide"
                            android:layout_width="match_parent"
                            android:layout_height="370dp"
                            app:layout_collapseMode="parallax" />

                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/tv_index"
                            android:layout_width="44dp"
                            android:layout_height="20dp"
                            android:layout_gravity="bottom|end"
                            android:layout_marginEnd="12dp"
                            android:layout_marginBottom="24dp"
                            android:background="@drawable/shape_000000_20_rect_10dp"
                            android:gravity="center"
                            android:text="@{module.tvIndexOb}"
                            android:textColor="@color/color_ffffff"
                            android:textSize="12sp"
                            app:fontFamily="@font/avenir_medium" />

                        <View
                            android:id="@+id/view_shadow"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="bottom"
                            android:background="@drawable/rectangle_goods_detail_shadow" />

                        <androidx.appcompat.widget.Toolbar
                            android:id="@+id/toolbar"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@android:color/transparent"
                            android:translationZ="1dp"
                            app:contentInsetEnd="0dp"
                            app:contentInsetStart="0dp"
                            app:contentInsetStartWithNavigation="0dp"
                            app:layout_collapseMode="pin"
                            app:titleMargin="0dp">

                            <include
                                android:id="@+id/layout_goods_detail_top"
                                layout="@layout/layout_goods_detail_top_v5"
                                bind:click="@{click}"
                                bind:module="@{module}" />
                        </androidx.appcompat.widget.Toolbar>

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

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

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="-12dp"
                    android:clipToPadding="false"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

            </androidx.coordinatorlayout.widget.CoordinatorLayout>

        </com.scwang.smartrefresh.layout.SmartRefreshLayout>

        <ImageButton
            android:id="@+id/iv_to_top"
            style="@style/goto_top_img_style"
            app:layout_constraintBottom_toTopOf="@+id/layout_goods_detail_bottom"
            app:layout_constraintEnd_toEndOf="parent" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/bottom_container"
            android:layout_width="match_parent"
            android:layout_height="87dp"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:visibility="visible">

            <!--购物车logo-->
            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/iv_detail_bottom_cart"
                android:layout_width="58dp"
                android:layout_height="52dp"
                android:background="@color/colorSurface"
                android:paddingStart="14dp"
                android:paddingEnd="14dp"
                android:scaleType="centerInside"
                android:singleClick="@{()->click.go2cart()}"
                android:src="@drawable/tabbar_cart_un_selected"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent" />

            <!--购物车数量-->
            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/cart_goods_count"
                android:layout_width="wrap_content"
                android:layout_height="15dp"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="10dp"
                android:background="@drawable/shape_cart_count_background"
                android:gravity="center"
                android:minWidth="15dp"
                android:paddingStart="3dp"
                android:paddingEnd="3dp"
                android:textColor="@color/color_ffffff"
                android:textSize="10sp"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="@+id/iv_detail_bottom_cart"
                app:layout_constraintTop_toTopOf="@+id/iv_detail_bottom_cart"
                tools:text="9"
                tools:visibility="visible" />

            <androidx.appcompat.widget.LinearLayoutCompat
                android:id="@+id/layout_buy"
                android:layout_width="0dp"
                android:layout_height="52dp"
                android:background="@color/colorSurface"
                android:gravity="center"
                android:orientation="horizontal"
                android:paddingStart="0dp"
                android:paddingEnd="6dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/iv_detail_bottom_cart">

                <View
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_weight="0.2"
                    app:isVisible="@{module.showBuyNowOb}"/>

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/button_add2cart"
                    style="@style/BuyButtonStyle_new"
                    android:layout_marginEnd="10dp"
                    android:enabled="@{module.isAdd2BagEnable}"
                    android:singleClick="@{(GoodsType.FLASH_SALE_UPCOMING == module.curGoodsType) ? click::flashSaleRemindMe : click::bottomAdd2Cart}"
                    android:text="@{module.bottomButtonContent}"
                    android:textColor="@{module.bottomTextColor}"
                    app:backgroundTint="@color/colorPrimary"
                    app:bindBackgroundTint="@{module.bottomButtonBackground}"
                    android:background="@drawable/btn_goods_detail_radius_shape"
                    tools:backgroundTint="@color/colorPrimary"
                    tools:enabled="true"
                    android:lineSpacingMultiplier="0.8"
                    tools:text="add to bag"
                    tools:textColor="@color/color_ffffff" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/button_buy_now"
                    style="@style/BuyButtonStyle_new"
                    android:layout_marginEnd="10dp"
                    android:enabled="@{module.isAdd2BagEnable}"
                    android:singleClick="@{()-> click.bottomBuyNowClick(false)}"
                    android:text="@string/app_common_buynow"
                    android:textColor="@{module.bottomTextColor}"
                    app:backgroundTint="@color/colorSecondary"
                    app:bindBackgroundTint="@{module.buyNowBgColor}"
                    android:background="@drawable/btn_goods_detail_radius_shape"
                    app:isVisible="@{module.showBuyNowOb}"
                    tools:backgroundTint="@color/colorSecondary"
                    tools:enabled="true"
                    tools:textColor="@color/color_ffffff" />

            </androidx.appcompat.widget.LinearLayoutCompat>

            <View
                android:layout_width="0dp"
                android:layout_height="@dimen/slender_divider_size"
                android:background="@color/color_e9e9e9"
                app:layout_constraintBottom_toTopOf="@+id/iv_detail_bottom_cart"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/tv_discount"
                android:layout_width="wrap_content"
                android:layout_height="26dp"
                android:background="@drawable/shape_eb474a_radius_13"
                android:gravity="center"
                android:paddingStart="10dp"
                android:paddingEnd="10dp"
                android:text="@{module.priceDiscountTip}"
                android:textColor="@color/color_ffffff"
                android:textSize="14sp"
                app:fontFamily="@font/avenir_medium"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:text="€4.99 - Saved €1.99" />

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/iv_discount_arrow"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_arrow_eb474a"
                app:layout_constraintEnd_toEndOf="@id/tv_discount"
                app:layout_constraintStart_toStartOf="@id/tv_discount"
                app:layout_constraintTop_toBottomOf="@id/tv_discount" />

            <androidx.constraintlayout.widget.Group
                android:id="@+id/group_discount"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:constraint_referenced_ids="tv_discount,iv_discount_arrow" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
wohelu666 commented 3 years ago

好的,谢谢