如何在 GridView 适配器中扩充布局

How to inflate a layout in GridView adapter

我已经在 GridView 中填充了一些 grid_items

我正在寻找一种方法来膨胀新布局(我们称之为 pop_up_layout.xml),它只会占据屏幕的一部分,单击按钮时应触发此事件放置在某个 grid_item 视图中。 我知道我必须将适配器中的功能放置在当前项目的位置。

我的目的是显示有关 grid_item 的更多信息,并通过正在膨胀的 pop_up_layout.xml 中的新按钮为用户提供新选项。

我已经搜索并浏览了 SO 和网站中的大部分相关问题,但我似乎找到了仅显示弹出视图的解决方案。

有人能指出我正确的方向吗? 我正在寻找 this 之类的东西。

您可以针对您的情况使用 DialogFragment 膨胀布局不是完美的答案。

要打开可以在单击网格项目时使用的片段

FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        BaseDialogFragment Fragment = new BaseDialogFragment();
        transaction.add(fragment, "loading");
        Bundle args = new Bundle();
        args.putString("your_data", yourdata);
// you can add as many string int or boolean. Explore it.
        fragment.setArguments(args);
        transaction.commitAllowingStateLoss();





     public class BaseDialogFragment extends DialogFragment {

            Typeface MR, MRR;

            @Override
            public void onViewCreated(View view, Bundle savedInstanceState) {
                super.onViewCreated(view, savedInstanceState);
                getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                getDialog().setCanceledOnTouchOutside(false);



            }

            @Override
            public void onStart() {

                super.onStart();

                Window window = getDialog().getWindow();
                WindowManager.LayoutParams windowParams = window.getAttributes();
                windowParams.dimAmount = 0.50f;

                window.setAttributes(windowParams);
            }

            public void onResume() {

                super.onResume();
                WindowManager.LayoutParams params = getDialog().getWindow().getAttributes();
                params.width = RelativeLayout.LayoutParams.MATCH_PARENT;
                params.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
                params.gravity = Gravity.CENTER;
                getDialog().getWindow().setAttributes(params);



            }

            @Nullable
            @Override
            public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

                View v = inflater.inflate(R.layout.yourlayout, container, false);

                // init your views here. or 
get the data here from the Grid View
                String your_data = getArguments().getString("your_data");

                return v;
            }
        }