直接上代码:
1 刚开始加载完界面,判断内容是否全部展示,.viewTreeObserver.addOnGlobalLayoutListener是为了保证控件view加载完成
nestedscrollview.viewTreeObserver.addOnGlobalLayoutListener {
if(!canScroll()){
mNext?.alpha = 1f
mNext?.isEnabled = true
}
}
/**
* 判断是否可以滚动 如果不可以滚动 返回false说明界面已经全部加载显示出来了;true则表示需要滑动 才显示全
*/
fun canScroll(): Boolean {
// val sv: ScrollView = findViewById(android.R.id.dtv_source_info_more_sv) as ScrollView
val child: View = nestedscrollview.getChildAt(0)
if (child != null) {
val childHeight = child.measuredHeight
return nestedscrollview.getHeight() < childHeight
}
return false
}
2 判断是否滑动到底部,来处理底部按钮是否可点击的状态
nestedscrollview?.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
Log.d("nestedscro scrollY->", scrollY?.toString())
Log.d("nestedscro oldScrollY->", oldScrollY?.toString())
// 判断顶部标题栏显示还是隐藏
if (scrollY >= 100) {
rl_focus_on_tanka_no_title?.visibility = View.GONE
rl_focus_on_tanka_title?.visibility = View.VISIBLE
view_space_top?.visibility = View.VISIBLE
} else {
rl_focus_on_tanka_no_title?.visibility = View.VISIBLE
rl_focus_on_tanka_title?.visibility = View.GONE
view_space_top?.visibility = View.GONE
}
// 滚动到底
if (scrollY == ((v as NestedScrollView).getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
mNext?.alpha = 1f
mNext?.isEnabled = true
}
}