2.2.1 release版本 xml里面的match_parent无效
Closed this issue · 28 comments
提issue前请去WIKI#常见问题找找相关问题,避免重复提问
提issue前请务必参考以下格式填写,否则该问题优先级将会降低
- 系统版本:
- 库版本:
- 问题描述/重现步骤:
- 问题代码/截图:
- 报错信息:
2.2.1 release版本。xml里面的match_parent无效,必须在代码里再设置一次setWidht(getScreenWidth())才行。2.2.0没有此问题
请提供demo代码
什么逻辑都没有的代码,测试发现2.2.0宽高正常,2.2.1会失效,无法全屏宽度或者全屏高度。最新的2.2.2.190916会直接崩溃。
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="match_parent"
android:background="@color/base_white"
android:orientation="vertical"
RelativeLayout
` public class SlideChapterDialogNew extends BasePopupWindow {
public SlideChapterDialogNew(Context context) {
super(context);
initView();
}
private void initView() {
setAlignBackground(true);
setKeepSize(true);
}
@Override
public View onCreateContentView() {
return createPopupById(R.layout.slide_choose_chapter_dialog);
}
} 崩溃信息如下
java.lang.NullPointerException: Attempt to read from field 'int android.graphics.Point.x' on a null object reference
at razerdp.util.PopupUiUtils.getScreenWidthCompat(PopupUiUtils.java:115)
at razerdp.basepopup.PopupDecorViewProxy.getAvaliableWidth(PopupDecorViewProxy.java:841)
at razerdp.basepopup.PopupDecorViewProxy.getMaskWidthSpec(PopupDecorViewProxy.java:409)
at razerdp.basepopup.PopupDecorViewProxy.measureNormal(PopupDecorViewProxy.java:242)
at razerdp.basepopup.PopupDecorViewProxy.onMeasure(PopupDecorViewProxy.java:230)
`
关于这方面我目前也正在重构,倒是candy那个报错我刚看了下确实有可能,我修复一下。
关于这方面我目前也正在重构,倒是candy那个报错我刚看了下确实有可能,我修复一下。
好的,麻烦了
别急着关嘛大兄得~我怕我忘了。
match_parent这个问题实际上新的代码已经解决了,但是会引发另一个问题,就是当剩余高度不足以显示的时候,同时非autoLocate的时候,popup必须得往返反向移动,这样极端情况下(比如popup是整个屏幕的高度这样子)会导致showPopupWindow(v)失效。
别急着关嘛大兄得~我怕我忘了。
好吧,那我先用2.2.1,然后自己算高度好了。
2.2.1版本,重写了showPopupWindow(View anchorView) 方法,在此方法里设置了高度,竟然都不生效。。
@Override public void showPopupWindow(View anchorView) { super.showPopupWindow(anchorView); Rect rect = new Rect(); anchorView.getGlobalVisibleRect(rect); int height = DeviceInfo.getScreenHeight() - rect.bottom; setHeight(height); }
这有点难受啊,高度怎么搞成在锚点view和底部导航栏充满呢
ya,所以这就是我最新版本重构的效果,,,,最新版本重构了对于match_parent的定义,当高度为match_parent的时候,如果有anchor,其高度就是anchor底部到可显示的底部(一般认为是屏幕底部)的高度。
不过这个版本还没发布,你急用的话我可以今晚发一个candy
不过这个版本还没发布,你急用的话我可以今晚发一个candy
那太棒了,最近正好要用。之前用的是2.2.0版本,挺稳定的,唯一的问题是横屏时右侧总有一部分区域无法被阴影遮住,然后这个bug在2.2.1修复了,结果今天发现2.2.1的match_parent无法生效。爆炸,现在没有能用的稳定版本了
更新到 candy 191101试试
测试后发现,不会崩溃,但是我希望的高度是popup在锚点view和导航栏中间,结果现在popup顶部高度都顶到了状态栏上面了。。使用的横屏设备进行测试的。
。。。你这是什么操作,看不懂,锚点view和导航栏中间?
比如说屏幕中间有个按钮,点击按钮显示popup,期待的效果是显示一个popup,popup显示在按钮下面并且底部和屏幕底部一致。但是测试发现,最新的测试版,popup设置高度为match_parent后,这个popup就直接全屏了,而没有在锚点view下方。
你刚刚不是说当高度为match_parent的时候,如果有anchor,其高度就是anchor底部到可显示的底部(一般认为是屏幕底部)的高度么,但是我测试发现,match_parent的时候,popup的高度是屏幕高度。(横屏和竖屏测试后发现,popup的高度都是屏幕的最小宽度)
噢,忘了跟你说。。。请加上setResize(true)
因为popup无法判定你到底是想全屏。。。还是想要剩余空间
噢,忘了跟你说。。。请加上setResize(true)
因为popup无法判定你到底是想全屏。。。还是想要剩余空间
加在构造方法里么,我加在构造方法里,并没有用啊。。
上什么逻辑都没有的测试代码。
-
TestPopup.java
public class TestPopup extends BasePopupWindow {public TestPopup(Context context) {
super(context);
setResize(true);
}@OverRide
public View onCreateContentView() {
return createPopupById(R.layout.layout_popup);
}
}
2.layout_popup.xml
<View
android:layout_width="200dp"
android:layout_height="match_parent"
android:background="#862727" />
3.activity_popup.xml
<Button
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
4.PopupActivity
public class PopupActivity extends BaseActivity {
public static void start(Context context) {
Intent starter = new Intent(context, PopupActivity.class);
context.startActivity(starter);
}
@Override
protected void init() {
findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new TestPopup(PopupActivity.this).showPopupWindow(R.id.btn1);
}
});
}
@Override
protected int getLayoutResId() {
return R.layout.activity_popup;
}
}
上什么逻辑都没有的测试代码。
- TestPopup.java
public class TestPopup extends BasePopupWindow {
public TestPopup(Context context) {
super(context);
setResize(true);
}
@OverRide
public View onCreateContentView() {
return createPopupById(R.layout.layout_popup);
}
}2.layout_popup.xml
<View android:layout_width="200dp" android:layout_height="match_parent" android:background="#862727" />
3.activity_popup.xml
<Button android:id="@+id/btn_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" />
4.PopupActivity
public class PopupActivity extends BaseActivity {public static void start(Context context) { Intent starter = new Intent(context, PopupActivity.class); context.startActivity(starter); } @Override protected void init() { findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new TestPopup(PopupActivity.this).showPopupWindow(R.id.btn1); } }); } @Override protected int getLayoutResId() { return R.layout.activity_popup; }
}
绝望,github把部分代码吃了
代码给你,https://pan.baidu.com/s/15u_uWQbQ1YCyZzSL2v5cKw、
依赖是最新的implementation 'com.github.razerdp:BasePopup_Candy:2.2.2.191101'
刚刚给的代码有个地方写错了,PopupActivity的点击事件,按钮id写错了,点击事件里面应该是 new TestPopup(PopupActivity.this).showPopupWindow(R.id.btn_1);
修改完之后测试,高度还是不对。
刚刚给的代码有个地方写错了,PopupActivity的点击事件,按钮id写错了,点击事件里面应该是 new TestPopup(PopupActivity.this).showPopupWindow(R.id.btn_1);
修改完之后测试,高度还是不对。
测试发现,2.2.0版本,不设置setKeepSize(true),是我想要的现象:竖直方向的位置是在按钮和屏幕底部中间。改为最新测试版,popup还是顶部贴着屏幕顶部了。
因为我发错了一次。