最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)之PopupWindow創(chuàng)建彈窗、對話框的方法詳解

 更新時間:2019年03月15日 11:41:45   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)之PopupWindow創(chuàng)建彈窗、對話框的方法,結(jié)合實例形式詳細(xì)分析了Android使用PopupWindow創(chuàng)建對話框相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)之PopupWindow創(chuàng)建彈窗、對話框的方法。分享給大家供大家參考,具體如下:

簡介:

PopupWindow 可創(chuàng)建類似對話框風(fēng)格的窗口

效果:

使用方法:

使用PopupWindow 創(chuàng)建對話框風(fēng)格的串口秩序如下兩步即可:

1. PopupWindow 的構(gòu)造器創(chuàng)建PopupWindow對象

2. PopupWindow 的showAsDropDown() 將其顯示效果設(shè)置為下拉顯示

3. PopupWindow 的showAtLoacation() 方法將PopupWindow() 在指定位置顯示出來

下拉顯示效果:

具體實現(xiàn)方法:

public class MainActivity extends Activity {
  private PopupWindow popupWindow;
  private View root;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    root = this.getLayoutInflater().inflate(R.layout.cell,null);//add cell.xml above you mainActivity window
    popupWindow = new PopupWindow(root,560,700);//create a popupWindow object
    root.findViewById(R.id.button01).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        //close the popupWindow
        popupWindow.dismiss();
      }
    });
  }
  public void send(View source){
    //set the location of PopupWindow
    popupWindow.showAtLocation(findViewById(R.id.send),Gravity.CENTER,20,20);//you can remove this effect
    //Use DropDown way to display
    popupWindow.showAsDropDown(root);
  }
}

mainActivity的布局文件:

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/idtatabHost"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_weight="1">
  <Button
    android:id="@+id/send"
    android:onClick="send"
    android:text="點我一下 有驚喜(嚇) 。。。"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

/layout/cell.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  android:id="@+id/cell"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="vertical">
  <ImageView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="9"
    android:src="@drawable/wechat"
    android:scaleType="fitXY"/>
  <Button
    android:id="@+id/button01"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#ffffffff"
    android:text="Close"
    android:textSize="15dp"/>
</LinearLayout>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論

宣汉县| 辽阳县| 二手房| 集安市| 明水县| 涟源市| 都昌县| 建湖县| 南宫市| 本溪| 吉木乃县| 皋兰县| 儋州市| 南华县| 郴州市| 如东县| 康乐县| 定陶县| 乌审旗| 大竹县| 图们市| 肇源县| 旬阳县| 盐城市| 华坪县| 靖江市| 西林县| 南部县| 容城县| 修水县| 思茅市| 房山区| 东莞市| 海原县| 湛江市| 温泉县| 武汉市| 林西县| 青田县| 华安县| 扶沟县|