我想移动并关闭我的弹出窗口,如facebook评论/像弹出窗口一样。我试过自己搜索但失败了。你可以帮我这么做吗。
我的代码:
int display_width=context.getResources().getDisplayMetrics().widthPixels;
int display_height=context.getResources().getDisplayMetrics().heightPixels;
final PopupWindow popupWindow=new PopupWindow(viewTmp_comment, display_width, display_height-60,true);
popupWindow.setOutsideTouchable(false);
popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
popupWindow.showAsDropDown(view);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupWindow.setTouchable(true);
popupWindow.showAtLocation(view, Gravity.CENTER,0,0);
popupWindow.setContentView(view);
popupWindow.getContentView().setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View view, DragEvent dragEvent) {
switch (dragEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
Toast.makeText(context,"Down",Toast.LENGTH_LONG).show();
popupWindow.dismiss();
break;
// case MotionEvent.ACTION_MOVE:
// Toast.makeText(context,"Up",Toast.LENGTH_LONG).show();
//// popupWindow.dismiss();
// break;
}
return false;
}
});
答案 0 :(得分:0)
Facebook对话框上升,因此您必须将其从当前位置翻译为顶部
<translate
android:fromYDelta="0%p"
android:toYDelta="-30%p"
android:duration="1000" />
关于动画,你应该看看:Android animation
更新: 定义你的风格:例如
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog"> <item name="android:windowAnimationStyle">@style/MyAnimation.Window</item> </style> <style name="MyAnimation.Window" parent="@android:style/Animation.Activity"> <item name="android:windowExitAnimation">@anim/slide_up</item> </style>
并设置popupWindow.setAnimationStyle(R.style.DialogTheme)而不是R.anim