2017-04-27 275 views
0

我想移動和/解僱我的彈出窗口,如Facebook評論一樣彈出窗口做。我嘗試了自己並搜索,但失敗了。你能幫我這麼做嗎?彈出窗口不動如Facebook評論/像彈出窗口做

我的代碼:

int display_width=context.getResources().getDisplayMetrics().widthPixels; 
       int display_height=context.getResources().getDisplayMetrics().heightPixels; 

       final PopupWindow popupWindow=new PopupWindow(viewTmp_comment, display_width, display_height-60,true); 
       popupWindow.setOutsideTouchable(false); 

       popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); 
       popupWindow.showAsDropDown(view); 
       popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
       popupWindow.setTouchable(true); 
       popupWindow.showAtLocation(view, Gravity.CENTER,0,0); 
       popupWindow.setContentView(view); 

       popupWindow.getContentView().setOnDragListener(new View.OnDragListener() { 
        @Override 
        public boolean onDrag(View view, DragEvent dragEvent) { 

         switch (dragEvent.getAction()) { 
          case MotionEvent.ACTION_DOWN: 
           Toast.makeText(context,"Down",Toast.LENGTH_LONG).show(); 
           popupWindow.dismiss(); 
           break; 

//      case MotionEvent.ACTION_MOVE: 
//      Toast.makeText(context,"Up",Toast.LENGTH_LONG).show(); 
////      popupWindow.dismiss(); 
//      break; 
         } 

         return false; 
        } 
       }); 

回答

0

Facebook的對話框上升,所以你必須把它從當前位置轉換到頂部

<translate 
    android:fromYDelta="0%p" 
    android:toYDelta="-30%p" 
    android:duration="1000" /> 

它是關於動畫,你應該看看:Android animation

更新: 定義你的風格:例如

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog"> <item name="android:windowAnimationStyle">@style/MyAnimation.Windo‌​w</item> </style> <style name="MyAnimation.Window" parent="@android:style/Animation.Activity"> <item name="android:windowExitAnimation">@anim/slide_up</item> </style> 

,並設置popupWindow.setAnimationStyle(R.style.DialogTheme)不R.anim

+0

窗口不動了一下 – AAA

+0

你添加動畫到您的對話框看法? –

+0

是的,我加入了一些動畫,但沒有奏效 – AAA