Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 330132662/3385ed1433c6ec35af6aabb9f13d16af to your computer and use it in GitHub Desktop.
Save 330132662/3385ed1433c6ec35af6aabb9f13d16af to your computer and use it in GitHub Desktop.
CoordinatorLayout+AppBarLayout+地点列表+地图 滑动冲突解决
<?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"
android:background="@color/green"
android:fitsSystemWindows="true"
tools:context="com.jh.charing.ui.frag.StationFrag">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior">
<!--关键点2 AppBarLayout需要配置行为:com.google.android.material.appbar.AppBarLayout$Behavior
否则地图上下滚动 会引起整个页面滚动
-->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/map_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dp"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/map_parent"
android:layout_width="match_parent"
android:layout_height="380dp"
android:minHeight="0dp"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
<com.hjq.bar.TitleBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:backButton="false"
app:barStyle="transparent"
app:layout_collapseMode="parallax"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_test_address"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:drawablePadding="5dp"
android:gravity="center_vertical"
android:text="中国"
android:textColor="@color/panda"
android:textSize="14sp" />
<!-- android:drawableRight="@drawable/tri_angle_down"
-->
<LinearLayout
android:id="@+id/tv_test_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@drawable/shape_home_search"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageView
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginLeft="10dp"
android:src="@drawable/serch" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:gravity="left"
android:hint="查找电站"
android:textColor="@color/gray"
android:textColorHint="@color/gray"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</com.hjq.bar.TitleBar>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/nest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pink"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!--关键点1 AppBarLayout之外的布局 根节点NestedScrollView + app:layout_behavior="@string/appbar_scrolling_view_behavior" -->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:behavior_fitToContents="false">
<!--筛选条件 点选 可能会改为列表 -->
<View
android:id="@+id/pull_v"
android:layout_width="80dp"
android:layout_height="4dp"
android:background="@color/gray"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.hjq.widget.layout.WrapRecyclerView
android:id="@+id/recy_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="标签列表"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pull_v" />
<TextView
android:id="@+id/station_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:text="@string/station_list"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recy_label" />
<TextView
android:id="@+id/nearby_title1_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="附近可用电站"
android:textColor="@color/text_gray"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/station_title_tv"
app:layout_constraintLeft_toRightOf="@+id/station_title_tv" />
<TextView
android:id="@+id/tv_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/arrows_right_ic"
android:gravity="center"
android:text="更多"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/nearby_title1_tv"
app:layout_constraintRight_toRightOf="parent" />
<!--电站列表-->
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/station_title_tv">
<com.hjq.widget.layout.WrapRecyclerView
android:id="@+id/station_recy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
private WrapRecyclerView station_recy;
station_recy = findViewById(R.id.station_recy);
station_recy.setLayoutManager(new LinearLayoutManager(getContext()));
// station_recy.setNestedScrollingEnabled(false);
stationAdapter = new StationAdapter(getContext());
stationAdapter.setOnItemClickListener(this);
station_recy.setAdapter(stationAdapter);
/** 这里面的只是把AppBarLayout 高度占比改一下 可选**/
float heightDp = getResources().getDisplayMetrics().heightPixels / 2;
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) appbarlayout.getLayoutParams();
lp.height = (int) heightDp;
appbarlayout.setLayoutParams(lp);
/** 这里面的只是把AppBarLayout 高度占比改一下 可选**/
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appbarlayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
// 必选 让AppBarLayout 内部的地图 可以拖拽 ,不会变为滚动事件
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
@Override
public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment