技术转载:android抽屉SlidingDrawer——wrap_content非全屏
来源:互联网 发布:算法竞赛 编辑:程序博客网 时间:2024/05/16 09:45
转自:http://blog.csdn.net/you_and_me12/article/details/7327030
SlidingDrawer的用法比较多,就不说明了。
如果设置了属性layout_height="wrap_content"是不起作用的,在原来的SlidingDrawer中的onMeasure()方法使得layout_height一直都是fill_parent,但是使用layout_height="固定高度"也是可以!
以下重写SlidingDrawer,实现如下效果图(右图效果):
代码:
/** * 使得SlidingDrawer在屏幕低端,而不会填满整个屏幕 * @author akai 2012-03-06 */ public class WrapSlidingDrawer extends SlidingDrawer { private boolean mVertical; private int mTopOffset; public WrapSlidingDrawer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL); mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0); mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL); } public WrapSlidingDrawer(Context context, AttributeSet attrs) { super(context, attrs); int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL); mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0); mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec); int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec); final View handle = getHandle(); final View content = getContent(); measureChild(handle, widthMeasureSpec, heightMeasureSpec); if (mVertical) { int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset; content.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode)); heightSpecSize = handle.getMeasuredHeight() + mTopOffset + content.getMeasuredHeight(); widthSpecSize = content.getMeasuredWidth(); if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth(); } else { int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset; getContent().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec); widthSpecSize = handle.getMeasuredWidth() + mTopOffset + content.getMeasuredWidth(); heightSpecSize = content.getMeasuredHeight(); if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight(); } setMeasuredDimension(widthSpecSize, heightSpecSize); } }
注释:本代码可以直接使用,不需修改,使用是把原来的<SlidingDrawer>标签修改为<packageName.WrapSlidingDrawer>即可。
- 技术转载:android抽屉SlidingDrawer——wrap_content非全屏
- android抽屉SlidingDrawer——wrap_content非全屏
- android抽屉SlidingDrawer——wrap_content非全屏
- android抽屉SlidingDrawer——错误显示
- Android UI开发第九篇——SlidingDrawer 抽屉效果
- Android UI开发第九篇——SlidingDrawer 抽屉效果
- Android UI开发第九篇——SlidingDrawer 抽屉效果
- android SlidingDrawer(抽屉)
- android-抽屉式界面slidingDrawer
- Android之SlidingDrawer滑动抽屉
- Android隐藏式抽屉SlidingDrawer
- Android之SlidingDrawer抽屉效果
- Android SlidingDrawer 滑动抽屉效果
- Android抽屉(SlidingDrawer)的实现
- Android之SlidingDrawer抽屉效果
- android 抽屉效果 (SlidingDrawer)
- 纯种的左侧抽屉——SlidingDrawer实现
- Android Launcher抽屉类SlidingDrawer的使用
- Android学习笔记之AndroidManifest.xml文件解析
- ie浏览器缓存问题
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)的一种解决方法
- 2012-6-27 知识总结
- HDU 1856 More is better 并查集 路径压缩
- 技术转载:android抽屉SlidingDrawer——wrap_content非全屏
- QT发布存在的问题
- 继电保护测试-常规继电器的测试
- Nand Flash本地加载根文件系统后telnet不能登录
- cocos2d开发之菜单CCMenu
- 答疑一个哥们的多线程问题关于 start()和run()
- FTP Server报出421错误
- 老外解读:为什么中国移动要和苹果合作
- The 12 Ties that Bind Long-Term Relationships