NestedScrollView 滑动渐变显示Title。
作者:互联网
根据NestedScrollView的滑动来渐变显示Title。
nestedScrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (nestedScrollView, i, i1, i2, i3) -> {
int height = dp2Px(45, getContext());
if (i1 <= 0) {
tv_title.setText("教师资格证");
tv_title.setAlpha(0);
} else if (i1 > 0 && i1 < height) {
tv_title.setText("教师资格证");
//获取渐变率
float scale = (float) i1 / height;
//获取渐变数值
float alpha = (1.0f * scale);
tv_title.setAlpha(alpha);
} else {
tv_title.setAlpha(1f);
}
});
标签:Title,i1,NestedScrollView,渐变,float,height,tv,title 来源: https://blog.csdn.net/qq_37492806/article/details/91867418