我在列表视图中使用自定义弹出窗口,此弹出窗口需要在触发器视图的高度和触发器视图的左侧中间绘制。
我能够实现第一部分,第二部分似乎难以捉摸,这是我的代码:
public class QuickAction implements View.OnTouchListener {
private View triggerView;
private PopupWindow window;
protected final WindowManager windowManager;
public QuickAction(View triggerView) {
this.triggerView = triggerView;
window = new PopupWindow(triggerView.getContext());
window.setTouchable(true);
window.setTouchInterceptor(this);
windowManager = (WindowManager) triggerView.getContext().getSystemService(Context.WINDOW_SERVICE);
ImageView imageView = new ImageView(triggerView.getContext());
imageView.setImageResource(R.drawable.ic_action_email);
LayoutInflater layoutInflater = (LayoutInflater) triggerView.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.quick_action_popup_layout, null, false);
window.setContentView(layout);
// window.setBackgroundDrawable(null);
window.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
window.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
window.setTouchable(true);
window.setFocusable(false);
window.setOutsideTouchable(true);
}
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.ACTION_OUTSIDE == event.getAction()) {
this.window.dismiss();
return true;
}
return false;
}
public void show() {
int[] location = new int[2];
triggerView.getLocationOnScreen(location);
window.showAtLocation(triggerView, Gravity.NO_GRAVITY, location[0] + (triggerView.getLeft()), location[1] + (triggerView.getHeight() / 2));
}
}
我想要的是将弹出窗口的右边缘与我的triggerview的左侧边缘对齐
Triggerview是我想要生成弹出窗口的按钮,代码的相关部分是:
public void show() {
int[] location = new int[2];
triggerView.getLocationOnScreen(location);
window.showAtLocation(triggerView, Gravity.NO_GRAVITY, location[0] + (triggerView.getLeft()), location[1] + (triggerView.getHeight() / 2));
}
然而,这并没有给我预期的结果。有任何想法吗?
答案 0 :(得分:1)
指定
$categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage; $category1 = new \VENDX\Items\Domain\Model\Category; //1st catobj $category1->setCatName('Cat1'); //First category $categories->attach($category1); $category2 = new \VENDX\Items\Domain\Model\Category; //2nd catobj $category2->setCatName('Cat2'); //Second category $categories->attach($category2); $item->setCategories($categories);
的重力与指定类似NO_GRAVITY
。
如果您想将弹出窗口的右侧放置在指定位置,则需要Gravity.LEFT | Gravity.TOP
而不是Gravity.TOP | Gravity.RIGHT
。