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

首頁 > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)底部彈窗效果

2019-10-23 18:27:37
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了Android實(shí)現(xiàn)底部彈窗效果的具體代碼,供大家參考,具體內(nèi)容如下

Android,彈窗

源代碼地址:https://github.com/luoye123/Box

東西很簡(jiǎn)單,我就直接亮代碼了:

1、activity_main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:id="@+id/ll_image"> <Button android:id="@+id/bt_select_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="選擇圖片" /></LinearLayout>

2、MainActivity.java

public class MainActivity extends AppCompatActivity implements View.OnClickListener { private SelectPicPopupWindow menuWindow; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.bt_select_image).setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()) {  case R.id.bt_select_image:  //TODO implement  selectImgs(); } } private void selectImgs(){ menuWindow = new SelectPicPopupWindow(MainActivity.this, itemsOnClick); //設(shè)置彈窗位置 menuWindow.showAtLocation(MainActivity.this.findViewById(R.id.ll_image), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); } private View.OnClickListener itemsOnClick = new View.OnClickListener() { public void onClick(View v) {  menuWindow.dismiss();  switch (v.getId()) {  case R.id.item_popupwindows_camera: //點(diǎn)擊拍照按鈕   break;  case R.id.item_popupwindows_Photo: //點(diǎn)擊從相冊(cè)中選擇按鈕   break;  default:   break;  } } };}

3、關(guān)鍵代碼:SelectPicPopupWindow.java

 **public class SelectPicPopupWindow extends PopupWindow {  private Button item_popupwindows_camera, //彈窗拍照按鈕   item_popupwindows_Photo,  //彈窗從相冊(cè)選擇按鈕   item_popupwindows_cancel;  //彈窗取消按鈕  private View menuview;  /**  * 上傳圖片*************************  * @param context  * @param itemsOnclick  */  public SelectPicPopupWindow(Activity context, View.OnClickListener itemsOnclick){  super(context);  LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  menuview = inflater.inflate(R.layout.item_popupwindows,null);  item_popupwindows_camera = (Button) menuview.findViewById(R.id.item_popupwindows_camera); //拍照按鈕  item_popupwindows_cancel = (Button) menuview.findViewById(R.id.item_popupwindows_cancel); //取消按鈕  item_**popupwindows_Photo = (Button) menuview.findViewById(R.id.item_popupwindows_Photo); //圖庫按鈕  /**   * 取消按鈕銷毀事件   */  item_popupwindows_cancel.setOnClickListener(new View.OnClickListener() {   public void onClick(View view) {   dismiss();   }  });  item_popupwindows_camera.setOnClickListener(itemsOnclick);  item_popupwindows_Photo.setOnClickListener(itemsOnclick);  //設(shè)置SelectPicPopupWindow的View  this.setContentView(menuview);  //設(shè)置SelectPicPopupWindow**彈出窗體的寬  this.setWidth(ViewGroup.LayoutParams.FILL_PARENT);  //設(shè)置SelectPicPopupWindow彈出窗體的高  //修改高度顯示,解決被手機(jī)底部虛擬鍵擋住的問題 by黃海杰 at:2015-4-30  this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);  //設(shè)置SelectPicPopupWindow彈出窗體可點(diǎn)擊  this.setFocusable(true);  //設(shè)置SelectPicPopupWindow彈出窗體動(dòng)畫效果  //this.setAnimationStyle(R.style);  //實(shí)例化一個(gè)ColorDrawable顏色為半透明  ColorDrawable dw = new ColorDrawable(0xb0000000);  //設(shè)置SelectPicPopupWindow彈出窗體的背景  this.setBackgroundDrawable(dw);  //menuview添加ontouchlistener監(jiān)聽判斷獲取觸屏位置如果在選擇框外面則銷毀彈出框  menuview.setOnTouchListener(new View.OnTouchListener() {   public boolean onTouch(View view, MotionEvent motionEvent) {   int height = menuview.findViewById(R.id.ll_popup).getTop();   int y = (int) motionEvent.getY();   if (motionEvent.getAction() == MotionEvent.ACTION_UP){    if (y<height){    dismiss();    }   }   return true;   }  });  } }**

寫的不好,請(qǐng)見諒,,下一期完成后期的工作!

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 潜江市| 搜索| 大荔县| 峨眉山市| 保康县| 印江| 吉木乃县| 武宣县| 克拉玛依市| 定西市| 永德县| 阿坝| 霞浦县| 刚察县| 美姑县| 新竹县| 柏乡县| 开鲁县| 奈曼旗| 鞍山市| 绍兴市| 天峻县| 顺昌县| 台北市| 新兴县| 收藏| 井陉县| 山阴县| 南昌市| 云霄县| 卫辉市| 珠海市| 镇巴县| 黄山市| 东辽县| 固阳县| 焦作市| 蕲春县| 吉木萨尔县| 文水县| 慈溪市|