我可以获取相对于Android中我的Activity的根布局的View的x和y位置吗?
是否可以知道a Spinner是开放还是关闭?如果有一些onOpenListener for Spinners会更好.
我试过像这样使用OnItemSelectedListener:
spinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
executeSomething();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Log.d("nothing" , "selected");
}
});
Run Code Online (Sandbox Code Playgroud)
我知道如果选择了某些东西,窗口将会关闭(在executeSomething()中).但是如果我在对话框外单击,我也不会收到通知,这也会关闭微调器
我正在尝试测试PopupWindow类.我创建了这个方法来显示弹出窗口:
public void showPopup(){
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popup = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popup.setOutsideTouchable(true);
popup.setTouchable(true);
popup.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("POPUP", event.toString());
if(event.getAction() == MotionEvent.ACTION_OUTSIDE){
popup.dismiss();
return true;
}
return true;
}
});
popup.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 200);
}
Run Code Online (Sandbox Code Playgroud)
弹出窗口正确显示,看起来Touch Interceptor似乎根本不起作用:我没有得到任何日志信息,当然如果按下它之外弹出窗口也不会消失.
我是否需要在弹出窗口或托管它的Activity中设置一些其他属性?