2012-04-08 51 views
9

Yêu cầu thiết kế là , có một listview, trong các mục của listview, có một nút, nhấn nút, và sau đó, để hiển thị một popupwindow trên nút, không phải dưới cùng.Làm cách nào để hiển thị PopupWindow ở phía trên nút (chế độ xem)?

Trong Android, sử dụng "showAsDropDown", hiển thị mặc định Popupwindow ở cuối nút (Xem hoặc neo). Nhưng nếu phần dưới không được hiển thị, Popupwindow sẽ hiển thị trên đầu nút (Xem hoặc neo).

onTop = (displayFrame.bottom - mScreenLocation[1] - anchor.getHeight() - yoff) <(mScreenLocation[1] - yoff - displayFrame.top); 

như vậy, tôi theo đến thời điểm này, để di chuyển mục tương ứng của nút bằng cách "setSelectionFromTop", chúng ta hãy phán quyết là không enougn để hiển thị trên dưới cùng của nút để đạt được hiệu quả.

Trong android 4.0.3, là Ok, việc chuyển mục, và popupwindow hiển thị vị trí mới và aboved, Nhưng, trong android 2.2, các popupwindow vẫn thấy báo chí ở đâu, chứ không phải vị trí sau khi di chuyển.

boolean onTop = (displayFrame.bottom - mScreenLocation[1] - v.getHeight() - 0) < (mScreenLocation[1] - 0 - displayFrame.top); 
if(!onTop){ 
mListMain.setSelectionFromTop(mListMain.getPositionForView(v),(displayFrame.bottom - v.getHeight() + displayFrame.top)/2); 
} 

có thể giúp tôi, cách để giải quyết nó .. T_T

Trả lời

5

có thể không giống nhau tình huống, nhưng giải pháp của tôi là:?!

public class BaloonView extends PopupWindow { 
    public BaloonView(Context context, View content) { 
     super(context); 
     setWidth(WindowManager.LayoutParams.WRAP_CONTENT); 
     setHeight(WindowManager.LayoutParams.WRAP_CONTENT); 
     setTouchable(true); 
     setFocusable(true); 
     setOutsideTouchable(true); 
     setTouchInterceptor(new View.OnTouchListener() { 
       @Override 
       public boolean onTouch(View v, MotionEvent event) { 
       if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { 
        BaloonView.this.dismiss();     
        return true; 
       }    
       return false; 
       } 
      }); 
    } 

    public void showUnderView(View view, View content) { 
     setBackgroundDrawable(view.getContext().getResources().getDrawable(R.drawable.popup_inline_error_holo_dark)); 
     FrameLayout container = new FrameLayout(view.getContext()); 
     container.addView(content); 
     setContentView(container); 
     int[] location = new int[2]; 
     view.getLocationOnScreen(location); 
     container.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); 
     int xoffset = view.getWidth()/2 - container.getMeasuredWidth()/2; 
     showAsDropDown(view, xoffset, 0); 
    } 
} 
+0

chúng tôi có thể hiển thị cửa sổ bật lên ngay trên neo? Trình bày cái này hiển thị bên dưới neo. –

Các vấn đề liên quan