项目中的底部浮层的弹出实现方案
来源:互联网 发布:淘宝发货后买家退款 编辑:程序博客网 时间:2024/05/21 20:23
1 在实际开放中,有类似如下的效果
的实现思路有2种
一种是 实用popupWindow 来实现,一种是实用 fragment
对于第一种方案的代码主要如下:
HotelIconPopUpWindow popUpWindow = new HotelIconPopUpWindow(mFragment.getActivity(), mItemModelList); popUpWindow.setAnchorView(mFragment.getActivity().getWindow().getDecorView());popUpWindow.showPopWindow();
这里我们将我门浮层的anchorView 设置为decorView
/** * @author bkhu */public class HotelIconPopUpWindow extends PopupWindow implements View.OnClickListener { private View mDialogView; private View mDropDownAnchorView; private Context mContext; private LinearLayout mIconContainer; private TextView mCloseIconTv; private ArrayList<IconItemModel> mItemIDList; public HotelIconPopUpWindow(Context context, ArrayList<IconItemModel> itemIDList) { mContext = context; mItemIDList = itemIDList; setContentView(createContentView()); setWidth(ViewGroup.LayoutParams.MATCH_PARENT); setBackgroundDrawable(new ColorDrawable(Color.parseColor("#B3000000"))); setOutsideTouchable(true); setFocusable(true); } public void setAnchorView(View anchor) { mDropDownAnchorView = anchor; } private int getMarginValue() { int screenHeight = DeviceUtil.getScreenHeight(); return Math.round(screenHeight * 0.38f); } private View createContentView() { ViewGroup contentView = new FrameLayout(mContext); contentView.setFocusable(true); contentView.setFocusableInTouchMode(true); mDialogView = LayoutInflater.from(mContext).inflate(R.layout.hotel_detail_icon_info_popupwindow_layout, null); mIconContainer = (LinearLayout) mDialogView.findViewById(R.id.icon_container); mCloseIconTv = (TextView) mDialogView.findViewById(R.id.close); mCloseIconTv.setOnClickListener(this); contentView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.BOTTOM; contentView.addView(mDialogView, lp); int padding = getMarginValue(); contentView.setPadding(0, padding, 0, 0); return contentView; } public void showPopWindow() { if (mDropDownAnchorView == null || mDropDownAnchorView.getWindowToken() == null) return; setWidth(ViewGroup.LayoutParams.MATCH_PARENT); setHeight(ViewGroup.LayoutParams.MATCH_PARENT); setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); showAtLocation(mDropDownAnchorView, Gravity.BOTTOM, 0, 0); mDialogView.setFocusable(true); mDialogView.setFocusableInTouchMode(true); loadAnimation(mDialogView, R.anim.common_hotel_popwindow_in, false); } @Override public void dismiss() { loadAnimation(mDialogView, R.anim.common_hotel_popwindow_out, true); } private void loadAnimation(View view, int resId, boolean isSetListener) { Animation animation = AnimationUtils.loadAnimation(mContext, resId); animation.setFillAfter(true); if (isSetListener) { animation.setAnimationListener(new EndAnimationListener()); } view.startAnimation(animation); } @Override public void onClick(View v) { int id = v.getId(); if (id == R.id.close) { dismiss(); } } private class EndAnimationListener implements Animation.AnimationListener { @Override public void onAnimationEnd(Animation animation) { new Handler().post(new Runnable() { @Override public void run() { if (isShowing()) { HotelIconPopUpWindow.super.dismiss(); } } }); } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { } }}
这里要注意的是,首先我门要给popUpWindow 设置背景,
setBackgroundDrawable(new ColorDrawable(Color.parseColor("#B3000000"))); setOutsideTouchable(true); setFocusable(true);
这里我们在弹起的时候会有相应的背景,注意这个背景一定要设置,如果不设置,点击背景的区域的点击消失的功能,将消失, setOutsideTouchable(true); 控制window 内容区域外的部分点击自动消失。
同时注意设置背景的宽高
setWidth(ViewGroup.LayoutParams.MATCH_PARENT); setHeight(ViewGroup.LayoutParams.MATCH_PARENT); setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
第二种方案,即是实用fragment
Bundle arguments = new Bundle(); arguments.putBoolean("isOversea",cacheBean.isOversea()); HotelFloatFacilitysFragment hotelFloatFacilitysFragment = new HotelFloatFacilitysFragment(); if(cacheBean.isOversea()){ hotelFloatFacilitysFragment.setOverseaContent(cacheBean.getHotelOverseaFloatFacilityTags()); }else{ hotelFloatFacilitysFragment.setInlandContent(cacheBean.getHotelInlandFloatFacilityTags()); } hotelFloatFacilitysFragment.setTargetFragment(mFragment,0); hotelFloatFacilitysFragment.setArguments(arguments); FragmentManager fragmentManager = mFragment.getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setCustomAnimations(R.anim.common_hotel_popwindow_in_3, R.anim.common_hotel_popwindow_out_3, R.anim.common_hotel_popwindow_in_3, R.anim.common_hotel_popwindow_out_3); transaction.add(android.R.id.content,hotelFloatFacilitysFragment,"HotelFloatFacilitysFragment") .addToBackStack("HotelFloatFacilitysFragment").commitAllowingStateLoss();
阅读全文
0 0
- 项目中的底部浮层的弹出实现方案
- 实现从底部弹出的PopupWindow
- 实现简单的弹出层
- 弹出层,遮罩层的实现
- html弹出层的实现
- 实现底部弹出菜单
- 底部弹出的pop
- Dialog 实现底部弹出菜单
- Android 实现底部弹出菜单
- PopupWindow实现屏幕底部弹出
- JavaScript弹出层效果的实现方法
- jQuery实现很炫很酷的弹出层效果
- jQuery实现很炫很酷的弹出层效果
- .net实现用户控件的弹出层
- JavaScript实现带遮罩的弹出层
- js实现div弹出层的方法
- 几种网页弹出层的实现
- 实现div层的弹出与拖动
- WeaveSocket框架-Unity太空大战游戏-服务端-1
- h5微信12牛牛房卡代理
- MAC pip install 权限错误解决办法.md
- Training RNNs as Fast as CNNs
- iOS 获取两段文字中间内容
- 项目中的底部浮层的弹出实现方案
- Centos 7 设置 SFTP
- 在Java中使用链接列表实现stack [译]
- springmvc 自定义拦截器实现未登录用户的拦截
- C++中vector用法详解
- spring Quartz 使用梳理
- vi编辑器须知
- 老徐小程序官方教程地址
- VB学习记录