就像这个
linkFAB 随着工具栏折叠而消失(标题折叠工具栏和应用程序栏下的 gif,在提供的链接中)我希望 imageview 上的这种行为而不是 FAB
类。 对于您的 ImageView,您可以在 AppBarLayout 上使用监听器,例如:
在你的活动中:
AppBarLayout appbarLayout = (AppBarLayout) findViewById(R.id.appbarlayoutid);
appbarLayout.addOnOffsetChangedListener( new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
float percentage = (appBarLayout.getTotalScrollRange()-(float)Math.abs(verticalOffset))/appBarLayout.getTotalScrollRange();
if(percentage < 0.3) {
mImageView.setVisibility(View.GONE)
} else if(percentage > 0.7) {
mImageView.setVisibility(View.VISIBLE)
}
});
希望这有帮助。