<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) {
//关闭
}
}
});