公司最近要实现一个类似于仿微博窗口弹出的效果,不同的是,要实现控件从顶部依次弹出,话不多说,先上效果图!
实现思路
- 将PopupWindow展示在屏幕上
- 遍历父布局,获得子布局View
- 为每个View设置进场动画及退场动画,利用Handler做延迟
1.展示PopupWindow
private void showWindow() {
View layout = getLayoutInflater().inflate(R.layout.window_popup, null);
final RelativeLayout relativeLayout = layout.findViewById(R.id.relative_popup);
relativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//添加退场动画
closeAnimation(relativeLayout);
}
});
popupWindow = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//添加进场动画
showAnimation(relativeLayout);
popupWindow.setOutsideTouchable(false);
popupWindow.setFocusable(false);
popupWindow.showAtLocation(