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

首頁 > 系統 > Android > 正文

Android PopupWindow使用實例

2020-04-11 11:30:13
字體:
來源:轉載
供稿:網友

示例效果如下:

 

MainActivity.xml

package sn.qdj.popupwindowdemo;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.PopupWindow;/** * PopupWindow使用 * @author qingdujun * */public class MainActivity extends ActionBarActivity {  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    /**     * popup.xml 為彈出界面布局     */    View root = getLayoutInflater().inflate(R.layout.popup, null);    /**     * 彈出界面     * 寬度:400     * 高度:200     */    final PopupWindow popup = new PopupWindow(root, 400,200);    Button btn = (Button)findViewById(R.id.btn);    Button close = (Button)findViewById(R.id.close);    btn.setOnClickListener(new OnClickListener() {  @Override  public void onClick(View v) {  // TODO Auto-generated method stub  /**   * 在指定位置彈出   *    * 第一個參數指定PopupWindow的錨點view,即依附在哪個view上。   * 第二個參數指定起始點為parent的右下角   * 第三個參數設置以btn的下方為原點,向左、上各偏移0像素。   */  popup.showAtLocation(findViewById(R.id.btn), Gravity.BOTTOM, 0, 0);  } });    close.setOnClickListener(new OnClickListener() {  @Override  public void onClick(View v) {  // TODO Auto-generated method stub  /**   * 關閉PopupWindow   */  popup.dismiss();  } });  }}


activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent" >  <Button    android:id="@+id/btn"    android:layout_width="200dp"    android:layout_height="wrap_content"    android:layout_alignParentTop="true"    android:text="彈出" />  <Button    android:id="@+id/close"    android:layout_width="200dp"    android:layout_height="wrap_content" android:layout_toRightOf="@id/btn"    android:text="關閉" /></RelativeLayout>

popup.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical" >  <Button    android:id="@+id/btn1"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:text="相冊" />  <Button    android:id="@+id/btn2"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:text="拍照" /></LinearLayout>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大竹县| 阳曲县| 富宁县| 梓潼县| 绥棱县| 治多县| 开平市| 宿松县| 安义县| 巨野县| 广饶县| 阿城市| 新乐市| 疏附县| 皮山县| 龙门县| 莱州市| 民乐县| 襄樊市| 盐池县| 临夏县| 呈贡县| 嘉鱼县| 临西县| 万源市| 区。| 台南市| 阿巴嘎旗| 巨野县| 界首市| 博罗县| 颍上县| 林口县| 石屏县| 三明市| 紫阳县| 苗栗县| 泸溪县| 贵港市| 齐河县| 海南省|