国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android開發之PopupWindow創建彈窗、對話框的方法詳解

2019-10-21 21:19:17
字體:
來源:轉載
供稿:網友

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

簡介:

PopupWindow 可創建類似對話框風格的窗口

效果:

Android開發,PopupWindow,彈窗,對話框

使用方法:

使用PopupWindow 創建對話框風格的串口秩序如下兩步即可:

1. PopupWindow 的構造器創建PopupWindow對象

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

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

下拉顯示效果:

Android開發,PopupWindow,彈窗,對話框

具體實現方法:

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>

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


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 托里县| 山阳县| 炎陵县| 清远市| 和林格尔县| 同德县| 昌宁县| 东港市| 来宾市| 工布江达县| 丁青县| 遵义县| 加查县| 建阳市| 武夷山市| 南溪县| 永和县| 全州县| 南康市| 龙州县| 巴彦淖尔市| 兴化市| 合作市| 梁山县| 怀远县| 潮安县| 景洪市| 彝良县| 广汉市| 赣州市| 阳曲县| 古浪县| 曲水县| 涟水县| 沙河市| 仁布县| 汉阴县| 汉阴县| 仁布县| 裕民县| 永福县|