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

Android PopupWindow使用實例

 更新時間:2015年06月09日 10:59:45   投稿:junjie  
這篇文章主要介紹了Android PopupWindow使用實例,本文直接給出代碼實例,需要的朋友可以參考下

示例效果如下:

 

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
  /**
   * 在指定位置彈出
   * 
   * 第一個參數(shù)指定PopupWindow的錨點view,即依附在哪個view上。
   * 第二個參數(shù)指定起始點為parent的右下角
   * 第三個參數(shù)設(shè)置以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
  /**
   * 關(guān)閉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="關(guān)閉" />
</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>

相關(guān)文章

最新評論

林周县| 阳新县| 龙门县| 山丹县| 尼木县| 抚宁县| 光泽县| 横山县| 西乌珠穆沁旗| 河南省| 文安县| 龙南县| 昭苏县| 时尚| 韶关市| 贡觉县| 赤水市| 英超| 嘉鱼县| 清新县| 中卫市| 棋牌| 浮山县| 拜城县| 临西县| 睢宁县| 凉城县| 贵阳市| 兴业县| 苍南县| 辉南县| 临夏县| 斗六市| 乡宁县| 贵州省| 连江县| 公主岭市| 溧水县| 镇安县| 宜昌市| 积石山|