红色卡片上滑出屏幕时,显示ToolBar姓名信息; 红色卡片下滑出ToolBar时,隐藏ToolBar
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_color">
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_color"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/id_buttom_view"
android:layout_marginTop="-57dip"
android:background="@drawable/bg_person"
android:orientation="vertical"
android:paddingTop="20dip">
</LinearLayout>
<RelativeLayout
android:id="@+id/id_buttom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/id_card_view_person_info"
android:layout_marginBottom="57dip"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/ic_group_50_copy" />
<androidx.cardview.widget.CardView
android:id="@+id/id_card_view_person_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="100dp"
android:layout_marginRight="20dp"
app:cardCornerRadius="10dp"
app:cardElevation="5dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="@drawable/group_50"
android:scaleType="centerCrop" />
</androidx.cardview.widget.CardView>
</RelativeLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
<RelativeLayout
android:id="@+id/relative_layout_user_name"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="invisible">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/ic_group_50_copy" />
<TextView
android:id="@+id/tv_tool_bar_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="12dp"
android:ellipsize="end"
android:gravity="center_horizontal"
android:lines="1"
android:text="userName"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
</FrameLayout>
viewBinding.scrollView.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
val distanceCardInfoView = viewBinding.idCardViewPersonInfo.top + viewBinding.idCardViewPersonInfo.measuredHeight
if (viewBinding.relativeLayoutUserName.visibility == View.INVISIBLE) {
if (scrollY >= distanceCardInfoView) {
viewBinding.relativeLayoutUserName.visibility = View.VISIBLE
}
} else {
val cardRect = Rect()
val toolBarRect = Rect()
viewBinding.idCardViewPersonInfo.getGlobalVisibleRect(cardRect)
viewBinding.relativeLayoutUserName.getGlobalVisibleRect(toolBarRect)
val cardBottom = cardRect.bottom
val toolBarBottom = toolBarRect.bottom
if (cardBottom > toolBarBottom) {
viewBinding.relativeLayoutUserName.visibility = View.INVISIBLE
}
}
}
|