如何滚动时使像谷歌播放淡入在动作条 [英] How to make a ActionBar like Google Play that fades in when scrolling
问题描述
如何制作透明或半透明的动作条,如谷歌播放淡入或缩小使用滚动时 windowActionBarOverlay
?
How to make transparent or translucent ActionBar like Google Play that fades in or out when scrolling using windowActionBarOverlay
?
查看下面的截图
推荐答案
以下是code我用的app我的工作
The following is the code I used in the app I am working
您必须使用 OnScrollChanged
功能在滚动型
。 动作条
不会让你设置不透明度,所以设置在动作条背景绘制,你可以根据滚动的滚动视图量改变其不透明度。我给一个工作流程示例
You will have to use the OnScrollChanged
function in your ScrollView
. ActionBar
doesn't let you set the opacity , so set a background drawable on the actionbar and you can change its opacity based on the amount of scroll in the scrollview. I have given an example workflow
该函数集给出了适当的字母的观点locationImage基于其位置WRT窗口。
The function sets gives the appropriate alpha for the view locationImage based on its position WRT window .
this.getScrollY()
给你多少滚动视图
已滚动
public void OnScrollChanged(int l, int t, int oldl, int oldt) {
// Code ...
locationImage.setAlpha(getAlphaForView(locationImageInitialLocation- this.getScrollY()));
}
private float getAlphaForView(int position) {
int diff = 0;
float minAlpha = 0.4f, maxAlpha = 1.f;
float alpha = minAlpha; // min alpha
if (position > screenHeight)
alpha = minAlpha;
else if (position + locationImageHeight < screenHeight)
alpha = maxAlpha;
else {
diff = screenHeight - position;
alpha += ((diff * 1f) / locationImageHeight)* (maxAlpha - minAlpha); // 1f and 0.4f are maximum and min
// alpha
// this will return a number betn 0f and 0.6f
}
// System.out.println(alpha+" "+screenHeight +" "+locationImageInitialLocation+" "+position+" "+diff);
return alpha;
}
编辑:我已经添加了一个例子工作的样品在 https://github.com/ramanadv/fadingActionBar ,你可以有看看吧。
EDIT : I have added an example working sample at https://github.com/ramanadv/fadingActionBar , you can have a look at it.
这篇关于如何滚动时使像谷歌播放淡入在动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!