2017-10-14 18 views
1

RecycleView 컨테이너 안에 튀어 나오는 사용자 정의 팝업 메뉴를 사용하고 있습니다.컨테이너 외부에 팝업 될 때 팝업 메뉴를 조절하는 방법

터치 한보기가 하단에있는 경우 팝업 메뉴는 RecycleView의 컨트롤을 숨 깁니다.

이 경우 팝업 위치를 조정하고 팝업이 정확히 인 정확한 거리를 가져 와서 메뉴가 컨테이너 내에 유지되도록.

이것은 쉽지만, 좌표를 얻고 항목 클릭 수를 처리하는 Adapter 내부에서 계산을 적용하는 데 어려움이 있습니다.

private void showPopupMenu(final View view, final int position) { 
    // inflate menu 
    final PopupMenu popup = new PopupMenu(view.getContext(), view); 
    popup.setGravity(Gravity.END); 
    MenuInflater inflater = popup.getMenuInflater(); 
    inflater.inflate(R.menu.popup_menu, popup.getMenu()); 
    popup.show(); 
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 

    final EditText editText = (EditText) promptView.findViewById(R.id.input_text); 
        // setup a dialog window 
     alertDialogBuilder.setCancelable(false) 
     .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, int id) { 

그리고 여기 결과입니다 :

void show(FragmentActivity activity, View touchedView, DataItem item) { 

     LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     final View popupView = layoutInflater.inflate(R.layout.popup_menu, null); 

     PopupWindow popupWindow = new PopupWindow(
       popupView, 
       ViewGroup.LayoutParams.WRAP_CONTENT, 
       ViewGroup.LayoutParams.WRAP_CONTENT); 

     popupWindow.setOutsideTouchable(true); 

     bind(popupWindow, popupView, item); 

     //draws the menu perfectly bellow the touched element,but doesn't take in account the parent view area 
     popupWindow.showAsDropDown(touchView); 

    } 

답변

0

발견. 2 상황이 진행 중이며 설명에 설명되어 있습니다.

void show(FragmentActivity activity, View touchView, IDataItem dataItem) { 

     LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     final View popupView = layoutInflater.inflate(R.layout.popup_menu, null); 

     PopupWindow popupWindow = new PopupWindow(
       popupView, 
       ViewGroup.LayoutParams.WRAP_CONTENT, 
       ViewGroup.LayoutParams.WRAP_CONTENT); 

     popupWindow.setOutsideTouchable(true); 

     bind(popupWindow, popupView, dataItem); 

     //1º problem: View item is inside ViewHolder.Item, so container is 2 levels up and touched item one level up. 
     View container = (View) touchView.getParent().getParent(); 
     View item = (View) touchView.getParent(); 

     int containerHeight = container.getHeight(); 

     //2º problem: to get size before the popup view is displayed: ref:https://stackoverflow.com/a/15862282/2700303 
     popupView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), 
       View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); 

     int yOff=0; 

     //if popup view will draw pass the bottom, get the amount needed to adjust the y coordinate 
     if (ContainerHeight < item.getHeight() + item.getTop() + popupView.getMeasuredHeight()) 
      yOff = ContainerHeight- (item.getTop() + item.getHeight() + popupView.getMeasuredHeight()); 

     popupWindow.showAsDropDown(touchView,0,yOff); 

    } 
0

이 내가 무슨 짓을 :

enter image description here

enter image description here

다음

내가 지금까지 관리하는 것입니다
+0

죄송하지만, 질문은 컨테이너 내부에 메뉴를 유지하는 방법입니다. 나는 당신이 그것에 어떻게 반응하는지 보지 못한다. – ByteArtisan

+0

오 스냅, 미안, 질문을 제대로 읽지 못했습니다. 그 죄송합니다.. –