【发布时间】:2021-12-26 22:39:18
【问题描述】:
我使用.showAsDropDown() 方法为 PopupWindow 充气,但我不确定为什么它不允许我左右移动它。上下移动时效果很好。
public class TestWindow extends PopupWindow {
private final Context context;
public TestWindow (Context context) {
super(context);
this.context = context;
setupView();
}
private void setupView() {
View view = LayoutInflater.from(context)
.inflate(R.layout.popup_window_wallet_options, null);
ButterKnife.bind(this, view);
setOutsideTouchable(true);
setFocusable(true);
setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.bgr_menu_clear_wallet));
setElevation(SpacingUtils.convertIntToDP(context, 4));
setContentView(view);
}
}
PopupWindow popupWindow = new TestWindow(context);
popupWindow.showAsDropDown(anchorButton, 50, -30);
将菜单向上移动 30 可以很好地工作,但我也试图将其向左移动但它不起作用。我做错了什么?
注意:
我已经用 50 和 -50 试过了,所以我不知道为什么它没有水平移动
我的R.layout.popup_window_wallet_options
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/bgr_menu_clear_wallet">
<TextView
android:id="@+id/tv_wallet_qr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?attr/selectableItemBackground"
android:padding="6dp"
android:text="Wallet QR"
android:textColor="@color/black" />
<TextView
android:id="@+id/tv_clear_wallet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?attr/selectableItemBackground"
android:padding="6dp"
android:text="Clear wallet"
android:textColor="@color/black" />
</LinearLayout>
【问题讨论】:
-
请忽略
...中的任何特殊属性。可能是什么原因造成的 -
我在上面的编辑中添加了我在
...中的内容。你试过我的弹出窗口吗?它对你有用吗? -
我无法重现此问题;但希望
showAtLocation()可以成为您的解决方法 -
.showAsDropdown()为您工作? (让你左右移动?) -
是的,工作正常。。你用的是普通按钮吗?还是选项菜单按钮?
标签: android popupwindow