2012-05-08 21 views
-1

私はアンドロイドを初めて使っています。ここに私の質問です。 アンドロイドでポップアップウィンドウを移動できますか?どのようにポップアップウィンドウや薬を飲むことができる他のダイアログを実装する。そして、このポップアップウィンドウは他のウィンドウをブロックできませんか?ポップアップすると、メインウィンドウで他の機能を引き続き使用できます。 Android:ポップアップウィンドウを移動して他のウィンドウをブロックしないようにする方法

は、以下のリンクを参照して、この目的のために、事前に

答えて

0

使用PopupWindowクラスをありがとう:ここ http://www.mobilemancer.com/2011/01/08/popup-window-in-android/

+0

私はこのリンクをチェックしましたが、そのポップアップウィンドウは麻薬にはなり得ません。指で動かすことはできますか? – ada

+0

x、yの位置を指定することでポップアップウィンドウの位置をコードで変更することができます – Krish

+0

ありがとう、私はちょうど我々がpositonsを変更するonTouchを定義することができます – ada

0

を、私は宣言するために、いくつかのコメントを私の仕事からのサンプルコードを作成する方法を、その作業

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       // your custom view 
      View popView = inflater.inflate(R.layout.pop_view, null); 
      // initialise your pop window 
      // take custom view , with specific width , height 
      PopupWindow popupWindow = new PopupWindow(popView, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true); 
      ImageView imageview = (ImageView) popView.findViewById(R.id.imageview); 
      Button dismiss = (Button) popView.findViewById(R.id.disbutton); 
      imageview.setImageURI(imagePath); 

    // button used to open pop window 
      popupWindow.showAsDropDown(ChooseFile, 50, -30); 

      // here is the part related to move popwindow  
      popView.setOnTouchListener(new View.OnTouchListener() { 
       @Override 
       public boolean onTouch(View view, MotionEvent event) { 

        int orgX = 0, orgY = 0; 
        int offsetX, offsetY; 


        switch (event.getAction()) { 

         case MotionEvent.ACTION_DOWN: 

          orgX = (int) event.getRawX(); 
          orgY = (int) event.getRawY(); 
          break; 

         case MotionEvent.ACTION_MOVE: 
          offsetX = (int) event.getRawX() - orgX; 
          offsetY = (int) event.getRawY() - orgY; 
          // update popwindow postion , -1 set for width & height to make it fixed not changed 
          popupWindow.update(offsetX, offsetY, -1, -1); 
          break; 

        } 

        return true; 
       } 
      }); 

      dismiss.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        // if you want dismiss your pop window 
        popupWindow.dismiss(); 
       } 
      }); 


     }