如何在坐标布局中修改 Imageview 的行为

问题描述 投票:0回答:1
我希望我的 imageView 在折叠工具栏达到一定高度时消失

就像这个

link

FAB 随着工具栏折叠而消失(标题折叠工具栏和应用程序栏下的 gif,在提供的链接中)我希望 imageview 上的这种行为而不是 FAB

java android android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout
1个回答
2
投票
Behavior

类。 对于您的 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) } });

希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.