将视图添加到RecyclerView中

时间:2017-08-29 10:02:39

标签: android android-recyclerview

点击RecyclerView中的Button时,我尝试将视图添加到ViewHolder

enter image description here

点击Button中的ViewHolder3时,视图(视图添加更多)将添加并显示为上图。

ViewAddMore会固定在那里,RecyclerView可以正常滚动。

我试过,但没有为我的问题找到任何解决方案; 对我的问题有任何建议吗?

1 个答案:

答案 0 :(得分:0)

请使用PopupWindow显示此视图。

// get a reference to the already created main layout
    LinearLayout mainLayout = (LinearLayout) findViewById(R.id.activity_main_layout);

    // inflate the layout of the popup window
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View popupView = inflater.inflate(R.layout.popup_window, null);

    // create the popup window
    int width = LinearLayout.LayoutParams.WRAP_CONTENT;
    int height = LinearLayout.LayoutParams.WRAP_CONTENT;
    boolean focusable = true; // lets taps outside the popup also dismiss it
    final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);

    // show the popup window
    popupWindow.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);

    // dismiss the popup window when touched
    popupView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            popupWindow.dismiss();
            return true;
        }
    });
  1. https://developer.android.com/reference/android/widget/PopupWindow.html

  2. How to make a simple android popup window?

  3. 希望这会对你有所帮助。