正常弹窗我们都会选择PopupWindow来实现 ,当我们有需求 需要在PopupWindow中嵌套Fragment+ViewPager 这个时候就会发现报错了 No view found for id 0x7f10013 并不是我们id写错了 错误的原因大概是:FragmentAdapter传入的是Activity的FragmentManger,默认是在Activity的布局xml中寻找ViewPager,但是实际上它是在弹出的View里定义的。最后的解决办法:用DialogFragment替代 DialogFragment全屏铺满 贴上代码public class MyDialogFragment extends DialogFragment { public MyDialogFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Holo_Light); //去出标题 getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); View inflate = inflater.inflate(R.layout.fragment_my_dialog, container, false); return inflate; } @Override public void onStart() { super.onStart(); Window win = getDialog().getWindow(); // 一定要设置Background,如果不设置,window属性设置无效 win.setBackgroundDrawable( new ColorDrawable(getResources().getColor(R.color.transparent))); DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics( dm ); WindowManager.LayoutParams params = win.getAttributes(); params.gravity = Gravity.BOTTOM; // 使用ViewGroup.LayoutParams,以便Dialog 宽度充满整个屏幕 params.width = ViewGroup.LayoutParams.MATCH_PARENT; params.height = ViewGroup.LayoutParams.WRAP_CONTENT; win.setAttributes(params); } }