<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                大家好,我們這一節講的是Android PopupWindow的使用! 在我理解其實PopupWindow其實類似于一個不能動的Widget(僅從顯示效果來說!) ? 它是浮在別的窗口之上的. ? 下面我將給大家做一個簡單的Demo,類似于音樂播放器的Widget的效果,點擊Button的時候出來PopupWindow,首先我們看一下效果圖: ? ![](https://box.kancloud.cn/2016-08-10_57aae5979bb5a.gif) ? ![](https://box.kancloud.cn/2016-08-10_57aae597ba537.gif) ? 下面是核心代碼: ? ~~~ package com.android.tutor;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup.LayoutParams;import android.widget.Button;import android.widget.PopupWindow;public class PopupWindowDemo extends Activity implements OnClickListener{ private Button btn; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn = (Button)findViewById(R.id.btn); btn.setOnClickListener(this); } @Override public void onClick(View v) { Context mContext = PopupWindowDemo.this; if (v.getId() == R.id.btn) { LayoutInflater mLayoutInflater = (LayoutInflater) mContext .getSystemService(LAYOUT_INFLATER_SERVICE); View music_popunwindwow = mLayoutInflater.inflate( R.layout.music_popwindow, null); PopupWindow mPopupWindow = new PopupWindow(music_popunwindwow, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); mPopupWindow.showAtLocation(findViewById(R.id.main), Gravity.RIGHT|Gravity.BOTTOM, 0, 0); } }} ~~~ 需要強調的是這里PopupWindow必須有某個事件觸發才會顯示出來,不然總會抱錯,不信大家可以試試! ? 隨著這個問題的出現,就會同學問了,那么我想初始化讓PopupWindow顯示出來,那怎么辦了,不去寄托于其他點擊事件, ? 在這里我用了定時器Timer來實現這樣的效果,當然這里就要用到Handler了,如果大家不理解的可以返回 ### [Android高手進階教程(九)之----Android Handler的使用!!](http://blog.csdn.net/Android_Tutor/archive/2010/05/08/5568806.aspx)看一看,加深了解: ? 下面是核心代碼: ? ~~~ package com.android.tutor;import java.util.Timer;import java.util.TimerTask;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup.LayoutParams;import android.widget.PopupWindow;public class PopupWindowDemo extends Activity{ private Handler mHandler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case 1: showPopupWindow(); break; } }; }; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //create the timer Timer timer = new Timer(); timer.schedule(new initPopupWindow(), 100); } private class initPopupWindow extends TimerTask{ @Override public void run() { Message message = new Message(); message.what = 1; mHandler.sendMessage(message); } } public void showPopupWindow() { Context mContext = PopupWindowDemo.this; LayoutInflater mLayoutInflater = (LayoutInflater) mContext .getSystemService(LAYOUT_INFLATER_SERVICE); View music_popunwindwow = mLayoutInflater.inflate( R.layout.music_popwindow, null); PopupWindow mPopupWindow = new PopupWindow(music_popunwindwow, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); mPopupWindow.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 0, 0); }} ~~~ ? 效果如下圖: ? ![](https://box.kancloud.cn/2016-08-10_57aae597d1661.gif) ? 這樣就可以初始化PopupWindow了,呵呵,這一節的布局文件有點多,如果大家想要源碼的話,留下你們的Email,我會盡快發送給大家的 ,今天就到這里,大家有什么不明白的歡迎留言!!!謝謝~ ? 要源碼的太多,我快崩潰了,所以上傳了。下載地址: [http://d.download.csdn.net/down/2871531/Android_Tutor](http://d.download.csdn.net/down/2871531/Android_Tutor)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看