安卓 协调者布局

 <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="10dp"
        app:layout_constraintBottom_toBottomOf="parent">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appbarlayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="@color/color_common_primary">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:collapsedTitleGravity="right"
                app:contentScrim="@color/color_common_white"
                app:expandedTitleGravity="center"
                app:layout_scrollFlags="scroll|snap|exitUntilCollapsed|enterAlwaysCollapsed">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <RadioGroup
                        android:id="@+id/radioGroup"
                        android:layout_width="match_parent"
                        android:layout_height="50dp"
                        android:gravity="center"
                        android:orientation="horizontal"
                        app:layout_constraintTop_toBottomOf="@+id/cons_config_info">

                        <RadioButton
                            android:background="@drawable/radiobutton_background"
                            android:button="@null"
                            android:enabled="false"
                            android:textColor="@color/radiobutton_text_color"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:text="序号"
                            android:textSize="16sp"/>

                        <RadioButton
                            android:background="@drawable/radiobutton_background"
                            android:button="@null"
                            android:enabled="false"
                            android:textColor="@color/radiobutton_text_color"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:text="零件编号"
                            android:textSize="16sp"/>
                        <RadioButton
                            android:background="@drawable/radiobutton_background"
                            android:button="@null"
                            android:textColor="@color/radiobutton_text_color"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:text="表头信息"
                            android:textSize="16sp" />
                        <RadioButton
                            android:background="@drawable/radiobutton_background"
                            android:button="@null"
                            android:checked="true"
                            android:textColor="@color/radiobutton_text_color"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:text="当前工序结果"
                            android:textSize="16sp" />
                    </RadioGroup>

                    <!--动态设置recyclerView的高度-->
                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/parts_recyclerView"
                        tools:itemCount="2"
                        tools:listitem="@layout/piweb_activity_parts_measure_parts_item"
                        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                        android:layout_width="match_parent"
                        android:layout_height="200dp"/>
                </LinearLayout>

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


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


        <androidx.core.widget.NestedScrollView
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <LinearLayout
                    android:id="@+id/ll_features_title"
                    app:layout_constraintTop_toBottomOf="@+id/parts_recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="#EDF2F7"
                    android:orientation="horizontal">
                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="@string/task_detail_number"
                        android:textColor="@color/color_common_black" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1.5"
                        android:gravity="center"
                        android:text="@string/task_detail_cate_name"
                        android:textColor="@color/color_common_black" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="@string/task_detail_value_type"
                        android:textColor="@color/color_common_black" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="@string/task_detail_nominal_number"
                        android:textColor="@color/color_common_black" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="@string/task_detail_top_tolerance"
                        android:textColor="@color/color_common_black" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="@string/task_detail_end_tolerance"
                        android:textColor="@color/color_common_black" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:gravity="center"
                        android:text="@string/task_detail_measured_value"
                        android:textColor="@color/color_common_black" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="@string/task_detail_determine_the_results"
                        android:textColor="@color/color_common_black" />

                </LinearLayout>
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/features_recyclerView"
                    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

在这里插入图片描述
在这里插入图片描述

注意截图的位置参数

AppBarLayout的监听方法


import com.google.android.material.appbar.AppBarLayout;

public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
    public enum State {
        EXPANDED,
        COLLAPSED,
        IDLE
    }
    private State mCurrentState = State.IDLE;

    @Override
    public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
        if (i == 0) {
            if (mCurrentState != State.EXPANDED) {
                onStateChanged(appBarLayout, State.EXPANDED);
            }
            mCurrentState = State.EXPANDED;
        } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
            if (mCurrentState != State.COLLAPSED) {
                onStateChanged(appBarLayout, State.COLLAPSED);
            }
            mCurrentState = State.COLLAPSED;
        } else {
            if (mCurrentState != State.IDLE) {
                onStateChanged(appBarLayout, State.IDLE);
            }
            mCurrentState = State.IDLE;
        }
    }
    public abstract void onStateChanged(AppBarLayout appBarLayout, State state);
}

使用

     binding.appbarlayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
            @Override
            public void onStateChanged(AppBarLayout appBarLayout, State state) {
                if (state == State.EXPANDED) {
                   //展开
                } else if (state == State.COLLAPSED) {
                    //关闭
                }
            }
        });
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值