Android showAsDropDown的诡异显示
来源:互联网 发布:淘宝网卖家中心官网 编辑:程序博客网 时间:2024/06/05 12:41
我们都知道showAsDropDown(View anchor,int xoff,int yoff)的用法,这是PopupWindow的一种显示方式,表示显示在anchor的正左下方,xoff与off表示x轴与y轴的偏移量。一般显示类似于微信
正常来说这样显示是没有问题的,不过今天我遇到了一个怪现象,它显示在了anchor的正左上方,特此来记录一下!
首先看我的布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_image_selector" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="200dp" /> <LinearLayout android:id="@+id/ll_bottom" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#000" android:orientation="horizontal"> <TextView android:id="@+id/tv_dir_name" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:padding="10dp" android:textColor="#fff" tools:text="sd/0/images" /> <TextView android:id="@+id/tv_dir_count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textColor="#fff" tools:text="5张" /> </LinearLayout></LinearLayout>
显示如下:
在activity中的代码如下:
dirListPopWindow = new PhotoDirListPopWindow(this, LayoutInflater.from(this).inflate(R.layout.layout_list_dir, null), ViewGroup.LayoutParams.MATCH_PARENT, (int) (mScreenHeight * 1.3), mFolders );
dirListPopWindow.showAsDropDown(llBottom, 0, 0);
显示结果如下:
现在改变一下布局文件:
<android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="280dp" />
仅改变了它的高度,其他的没变,显示结果如下:
结果可以看到,明明调用的是showAsDropDown方法,结果显示在了正左上方,通过反复的几次验证,得出一下结论:
当调用showAsDropDown(View anchor, int xoff, int off)时,anchor控件所在屏幕下方的高度记为mBottomHeight,
它距离上方的位置记录为mTopHeight,PopupWindow的高度记为mHeight
1,当mBottomHeight > mHeight时,显示在正下方
2,当mBottomHeight < mHeight时,但是mBottomHeight > mTopHeight时,显示在正下方
3,当mBottomHeight < mHeight时,但是mBottomHeight < mTopHeight时,显示在正上方
以上是使用showAsDropDown时遇到的比较怪异的显示。
阅读全文
2 0
- Android showAsDropDown的诡异显示
- android showAsDropDown的用法属性介绍
- android popupwindow showAsDropDown offsetx无效的问题
- Android下PopupWindow隐藏及显示(showAtLocation/showAsDropDown)
- Android下PopupWindow隐藏及显示(showAtLocation/showAsDropDown)
- Android下PopupWindow隐藏及显示(showAtLocation/showAsDropDown)
- Android开发之PopupWindow的showAtLocation()和showAsDropDown()
- 解决android 7.0 popwindow的showAsDropDown没有效果问题
- 在Android 7.0上PopupWindow.showAsDropDown不起作用的解决方法
- 在Android 7.0上PopupWindow.showAsDropDown不起作用的解决方法
- 在Android 7.0上PopupWindow.showAsDropDown不起作用的解决方法
- Android 7.0 PopupWindow 的showAsDropDown(View v)适配
- Eclipse 显示诡异的符号
- PopWindow的showAsDropDown在7.0手机上显示位置错乱问题
- Popupwindow的showAsDropDown方法详解
- 关于网页显示的一个诡异问题
- getYear函数引起“诡异”的时间显示
- PopupWindow显示showAsDropDown和showAtLocation区别
- Maven学习笔记 --- Maven入门笔记二
- Android 块设备驱动之二
- chrt命令
- WebLogic使用总结(六)——WebLogic创建虚拟主机和修改启动端口号
- mac 端口被占用 解决办法
- Android showAsDropDown的诡异显示
- 集合相关值描述
- Android自定义控件——View的测量模式
- 在VS中导出python第三方包
- Linux系统下手动创建用户的详细步骤
- oracle得到汉字首字母
- mysql 日期转换函数
- Linux---用户组
- android7.0闪退问题java.lang.SecurityException: MODE_WORLD_READABLE no longer supported