华为手机使umeng分享popwindow被底部导航栏挡住问题
2015-12-20 15:57
405 查看
本人也是刚学Android不久,刚刚实习在工作中遇到umeng分享被底部导航栏挡住的问题,不知道怎么解决,后来经过多番纠结在巧合的情况下发下来了这个方法,验证了一些手机发现可以,所以在此和大家分享一下。
其实这个问题也很简单就是在被挡住的手机上面做一个popwindow的偏移,但问题是如何判断在那些手机上需要偏移,总不能在所有手机上都偏移吧
解决方法:
比较decorview与screenview的高度 如果decorview大于screenview
则 popupWindow.showAtLocation(linearLayout, Gravity.BOTTOM, 0, -getNavigationBarHeight());
否则popupWindow.showAtLocation(linearLayout, Gravity.BOTTOM, 0, 0);
这样就解决了,哈哈哈
然而你真的以为这样就行了吗?并没有 过几天测试妹子就来找我了 说我程序有bug popwindow还是会被底部导航栏挡住,我就说不可能啊,我明明就测试过了,而且显示正常。所以我就去看看她到底是怎么测试的,结果发现,你妹 华为手机的底部导航栏是可以设置隐藏的。所以我写的程序果然有问题。如果隐藏导航栏,在弹出popwindow时再将导航栏显示出来会挡住popwindow,而如果一开始将导航栏显示,弹出popwindow后再将导航栏隐藏,底部就会空出一部分,非常难看。所以还是要接着改。
解决方法:
每次导航栏消失或者显示都会使view重新绘制 所以我在popwindow的contentview(我的是linearlayout)上做了些改动,在这个contentview的Onlayout方法里面判断是否需要偏移,如果偏移就设置这个contentview.setPadding(0,0,0,getNavigationBarHeight());不偏移就正常显示contentview.setPadding(0,0,0,0);
代码:
其实这个问题也很简单就是在被挡住的手机上面做一个popwindow的偏移,但问题是如何判断在那些手机上需要偏移,总不能在所有手机上都偏移吧
解决方法:
比较decorview与screenview的高度 如果decorview大于screenview
则 popupWindow.showAtLocation(linearLayout, Gravity.BOTTOM, 0, -getNavigationBarHeight());
否则popupWindow.showAtLocation(linearLayout, Gravity.BOTTOM, 0, 0);
这样就解决了,哈哈哈
然而你真的以为这样就行了吗?并没有 过几天测试妹子就来找我了 说我程序有bug popwindow还是会被底部导航栏挡住,我就说不可能啊,我明明就测试过了,而且显示正常。所以我就去看看她到底是怎么测试的,结果发现,你妹 华为手机的底部导航栏是可以设置隐藏的。所以我写的程序果然有问题。如果隐藏导航栏,在弹出popwindow时再将导航栏显示出来会挡住popwindow,而如果一开始将导航栏显示,弹出popwindow后再将导航栏隐藏,底部就会空出一部分,非常难看。所以还是要接着改。
解决方法:
每次导航栏消失或者显示都会使view重新绘制 所以我在popwindow的contentview(我的是linearlayout)上做了些改动,在这个contentview的Onlayout方法里面判断是否需要偏移,如果偏移就设置这个contentview.setPadding(0,0,0,getNavigationBarHeight());不偏移就正常显示contentview.setPadding(0,0,0,0);
代码:
/** * Created by wyq on 2015/12/16. */ public class MyLinearLayout extends LinearLayout { private static final String TAG ="CustomShareBoard"; private Context context; public MyLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); this.context= context; } public MyLinearLayout(Context context) { super(context); this.context= context; } public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); this.context= context; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { if(!isOffset()) { L.i(TAG,"不需要偏移"); if (this.getPaddingBottom()!=0) { this.setPadding(0, 0, 0, 0); } } else{ L.i(TAG, "需要偏移"); this.setPadding(0, 0, 0, getNavigationBarHeight()); invalidate();//这个一定要加上 不然会出错 我也不知道为什么如果有人找到原因请回复我 在此先谢过了 } super.onLayout(true, l, t, r, b); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); } private int getNavigationBarHeight() { Resources resources = this.context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); return resources.getDimensionPixelSize(resourceId); } public boolean isOffset() { return getDecorViewHeight() > getScreenHeight(); } public int getDecorViewHeight(){ return ((Activity)this.context).getWindow().getDecorView().getHeight(); } public int getScreenHeight(){ DisplayMetrics dm = new DisplayMetrics(); ((Activity)this.context).getWindowManager().getDefaultDisplay().getMetrics(dm);//当前activity return dm.heightPixels; } }
相关文章推荐
- Android架构简洁之道
- 【Linux】lvm基础操作
- oop实现方法与属性继承
- 部署和调优 2.3 tomcat中JDK安装
- 快速搭建网站教程
- ldd3 sbull编译遇到的问题 解决(部分)方法
- linux下获取域名的IP地址
- debian安装nginx-1.9.9和php-7.0.1
- shell脚本错误:syntax error near unexpected token '$'\r''
- Win7 Eclipse调试Centos Hadoop2.2-Mapreduce(转)
- awk 输出值到多个变量
- linux 设置wifi热点
- 2.在虚拟机上用iso制作yum源,及问题repomd.xml找不到解决
- Linux w 命令
- scala-31:Option使用和实现内幕源码揭秘
- 怎么搭建个人博客网站——我的建站过程
- Linux安装pecl和pear
- linux 环境变量设置三种方法和查看
- linux学习笔记
- 利用CDLinux里面的水滴破解路由器密码的教程