PopupWindow

A popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.
//定义
View popView = getLayoutInflater().inflate(R.layout.mypopview, null); //mypopview 自行定义
PopupWindow popupWindow = new PopupWindow(popView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//还可以通过 popupWindow。setContentView(popView);重新设置

//添加出现和消失动画
popupWindow.setAnimationStyle(R.style.myPopupAnimation);
//styel myPopupAnimation 在style.xml里的定义示例
<style name="myPopupAnimation" parent="android:Animation">
<item name="android:windowEnterAnimation">
@anim/popup_up_in</item>
<item name="android:windowExitAnimation">
@anim/popup_down_out</item>
</style>
//popup_up_in.xml定义示例
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotY="100%p"
android:duration="300" />
</set>
//popup_down_out.xml定义示例
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotY="100%p"
android:duration="300" />
</set>
//popupwindow挡住键盘解决办法
popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//显示位置
showAsDropDown(View anchor, int xoff, int yoff)
//Display the content view in a popup window anchored to the bottom-left corner of the anchor view offset by the specified x and y coordinates.
void showAsDropDown(View anchor)
//Display the content view in a popup window anchored to the bottom-left corner of the anchor view.
void showAtLocation(View parent, int gravity, int x, int y)
//Display the content view in a popup window at the specified location.

参考链接:http://developer.android.com/reference/android/widget/PopupWindow.html

标签: none

评论已关闭