转载仅供本人存档及后续研究使用,请尊重原创。
转载自:https://blog.csdn.net/niubitianping/article/details/52425003
Android 侧滑菜单栏SlidingMenu优化实现(SlidingMenu + FragmentTabHost)
博客地址:https://blog.csdn.net/qq941263013/article/details/81116930
优化后的开源库下载地址(https://download.csdn.net/download/qq941263013/10551527)
public void setOffsetFadeDegree(float f) {
mViewBehind.setOffsetFadeDegree(f);
}
private float mOffsetFadeDegree;
public void setOffsetFadeDegree(float degree) {
if (degree > 1.0f || degree < 0.0f)
throw new IllegalStateException("The offsetFadeDegree must be between 0.0f and 1.0f");
mOffsetFadeDegree = degree;
}
/**
* 绘制剩余View的淡出淡入
* @param content 主界面
* @param canvas 画布
* @param openPercent 打开了的百分比
*/
public void drawOffsetFade(View content, Canvas canvas, float openPercent) {
if (mWidthOffset <= 0 || mOffsetFadeDegree <= 0) return; //不开启就返回,不设置 淡入淡出效果
final int alpha = (int) (mOffsetFadeDegree * 255 * Math.abs(openPercent));
mFadePaint.setColor(Color.argb(alpha, 0, 0, 0));
canvas.drawRect(content.getLeft(), 0,content.getRight(), getHeight(), mFadePaint);
}
/**
* 绘制ui
* @param canvas
*/
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
// Draw the margin drawable if needed.
mViewBehind.drawShadow(mContent, canvas);
mViewBehind.drawFade(mContent, canvas, getPercentOpen()); //绘制剩余View的淡入淡出
mViewBehind.drawOffsetFade(mContent, canvas, getPercentOpen());
mViewBehind.drawSelector(mContent, canvas, getPercentOpen()); //
}
在初始化menu的时候,调用下面这个方法,设置透明度就行了,一般设置为0.4就行了
menu.setOffsetFadeDegree(0.4f);
---------------------------------------------------------------------------------------------------------------------------
早计划,早准备,早完成。 欢迎关注!交流!Star!
GitHub:https://github.com/wangyang0313
微信公众号:一个灵活的胖子MrWang
简书:https://www.jianshu.com/u/e5e733d79b96