Android 当浮动按钮到达NestedScrollView内TextView的相同高度位置时,如何将浮动按钮可见性设置为GONE?
我有以下XML文件-Android 当浮动按钮到达NestedScrollView内TextView的相同高度位置时,如何将浮动按钮可见性设置为GONE?,android,floating-action-button,nestedscrollview,Android,Floating Action Button,Nestedscrollview,我有以下XML文件- 我试图实现一种逻辑,当浮动条到达名为-活动\产品\页面\共享\文本视图时,它将消失。我曾尝试在NestedScrollView上实现新的NestedScrollView.OnScrollChangeListener(),但我从scrollX和scrollY获得的值完全不相关-它似乎根据当前可用的屏幕不动产和(可能)计算值也根据我的滚动速度-绝对不是根据NestedScrollView视图组 另外,我希望浮动条在文本视图的Y位置以下时返回。 通过一些简单的淡入/淡出动画显
我试图实现一种逻辑,当浮动条到达名为-活动\产品\页面\共享\文本视图时,它将消失。我曾尝试在NestedScrollView上实现新的NestedScrollView.OnScrollChangeListener()
,但我从scrollX和scrollY获得的值完全不相关-它似乎根据当前可用的屏幕不动产和(可能)计算值也根据我的滚动速度-绝对不是根据NestedScrollView视图组
另外,我希望浮动条在文本视图的Y位置以下时返回。
通过一些简单的淡入/淡出动画显示和消失
我如何实现它 也许是这样的?需要一些优化(例如,浮动按钮不需要位于每个滚动条上),但这与想法有关
activity_product_page_nested_scroll_view.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { _, _, _, _, _ ->
val locationOfTextView = IntArray(2)
val locationOfFloatingButton = IntArray(2)
activity_product_page_share_textview.getLocationInSurface(locationOfTextView)
activity_product_page_share_product_action_button.getLocationInSurface(
locationOfFloatingButton
)
if (locationOfTextView[1] >= locationOfFloatingButton[1] &&
locationOfTextView[1] + activity_product_page_share_textview.height <= locationOfFloatingButton[1] + activity_product_page_share_product_action_button.height
) {
if (activity_product_page_share_textview.alpha == 1F)
activity_product_page_share_textview.animate().alpha(0F).setDuration(200L).start()
} else {
if (activity_product_page_share_textview.alpha < 1F)
activity_product_page_share_textview.animate().alpha(1F).setDuration(200L).start()
}
})
activity\u product\u page\u nested\u scroll\u view.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener{{},{,},{,},{,},{,}
val locationOfTextView=IntArray(2)
val位置卸载按钮=阵列(2)
活动\产品\页面\共享\文本视图。GetLocationInsureFace(文本视图的位置)
活动\产品\页面\共享\产品\操作\按钮。GetLocationInsuranceFace(
位置卸载按钮
)
if(locationOfTextView[1]>=locationOfFloatingButton[1]&&
textview[1]的位置+活动\产品\页面\共享\ textview.height