国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Android - Android Animation實戰之屏幕底部彈出PopupWindow

Android Animation實戰之屏幕底部彈出PopupWindow

2021-05-07 16:16無緣公子 Android

這篇文章主要為大家介紹了Android Animation動畫實戰項目,屏幕底部彈出PopupWindow,如何實現?文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

android動畫的一個實戰內容,從屏幕底部滑動彈出popupwindow。 相信這種效果大家在很多app上都遇到過,比如需要拍照或者從sd卡選擇圖片,再比如需要分享某些東西時,大多會采用這么一種效果:

Android Animation實戰之屏幕底部彈出PopupWindow

那這種效果如何實現呢?
我們仿寫一個這種效果的實例吧:

Android Animation實戰之屏幕底部彈出PopupWindow

1)我們首先定義一下,彈出窗口的頁面布局組件:take_photo_pop.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?xml version="1.0" encoding="utf-8"?>
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:gravity="center_horizontal"
  android:orientation="vertical">
 
  <linearlayout
    android:id="@+id/pop_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:layout_alignparentbottom="true"
    android:gravity="center_horizontal"
    android:orientation="vertical">
 
    <textview
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:clickable="false"
      android:gravity="center"
      android:text="修改頭像"
      android:textcolor="#8a8a8a"
      android:textsize="15sp" />
 
    <view
      android:layout_width="fill_parent"
      android:layout_height="0.1dp"
      android:layout_marginleft="10dp"
      android:layout_marginright="10dp"
      android:background="#00c7c0" />
 
    <button
      android:id="@+id/btn_take_photo"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="拍照"
      android:textcolor="#0e61aa"
      android:textsize="18sp" />
 
    <button
      android:id="@+id/btn_pick_photo"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="從相冊選擇"
      android:textcolor="#0e61aa"
      android:textsize="18sp" />
 
    <button
      android:id="@+id/btn_cancel"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginbottom="15dip"
      android:layout_margintop="15dip"
      android:text="取消"
      android:textcolor="#0e61aa"
      android:textsize="18sp"
      android:textstyle="bold" />
  </linearlayout>
 
</relativelayout>

2)現在定義動畫,要知道該popupwindow出現時是從頁面底部向上滑動,消失時是從上向下滑動消失,,所以我們需要定義兩個動畫文件:
退出動畫pop_exit_anim.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <translate
    android:duration="200"
    android:fromydelta="0"
    android:toydelta="50%p" />
  <alpha
    android:duration="200"
    android:fromalpha="1.0"
    android:toalpha="0.0" />
</set>
顯示動畫pop_enter_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
 
  <translate
    android:duration="200"
    android:fromydelta="100%p"
    android:toydelta="0" />
  <alpha
    android:duration="200"
    android:fromalpha="0.0"
    android:toalpha="1.0" />
</set>

關于這兩個動畫,此處不再多做解析,讀過我之前博文的都應該知道啦,很簡單的,若是看不懂?請點擊此文上方的鏈接學習之。
3)自定義彈出框popupwindow:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import android.content.context;
import android.graphics.drawable.colordrawable;
import android.view.layoutinflater;
import android.view.motionevent;
import android.view.view;
import android.widget.button;
import android.widget.popupwindow;
import android.widget.relativelayout;
 
public class takephotopopwin extends popupwindow {
 
  private context mcontext;
 
  private view view;
 
  private button btn_take_photo, btn_pick_photo, btn_cancel;
 
 
  public takephotopopwin(context mcontext, view.onclicklistener itemsonclick) {
 
    this.view = layoutinflater.from(mcontext).inflate(r.layout.take_photo_pop, null);
 
    btn_take_photo = (button) view.findviewbyid(r.id.btn_take_photo);
    btn_pick_photo = (button) view.findviewbyid(r.id.btn_pick_photo);
    btn_cancel = (button) view.findviewbyid(r.id.btn_cancel);
    // 取消按鈕
    btn_cancel.setonclicklistener(new view.onclicklistener() {
 
      public void onclick(view v) {
        // 銷毀彈出框
        dismiss();
      }
    });
    // 設置按鈕監聽
    btn_pick_photo.setonclicklistener(itemsonclick);
    btn_take_photo.setonclicklistener(itemsonclick);
 
    // 設置外部可點擊
    this.setoutsidetouchable(true);
    // mmenuview添加ontouchlistener監聽判斷獲取觸屏位置如果在選擇框外面則銷毀彈出框
    this.view.setontouchlistener(new view.ontouchlistener() {
 
      public boolean ontouch(view v, motionevent event) {
 
        int height = view.findviewbyid(r.id.pop_layout).gettop();
 
        int y = (int) event.gety();
        if (event.getaction() == motionevent.action_up) {
          if (y < height) {
            dismiss();
          }
        }
        return true;
      }
    });
 
 
    /* 設置彈出窗口特征 */
    // 設置視圖
    this.setcontentview(this.view);
    // 設置彈出窗體的寬和高
    this.setheight(relativelayout.layoutparams.match_parent);
    this.setwidth(relativelayout.layoutparams.match_parent);
 
    // 設置彈出窗體可點擊
    this.setfocusable(true);
 
    // 實例化一個colordrawable顏色為半透明
    colordrawable dw = new colordrawable(0xb0000000);
    // 設置彈出窗體的背景
    this.setbackgrounddrawable(dw);
 
    // 設置彈出窗體顯示時的動畫,從底部向上彈出
    this.setanimationstyle(r.style.take_photo_anim);
 
  }
}

    定義要彈出的組件takephotopopwin,它繼承自popupwindow,具體如何實現的,我備注信息很詳細了。 有一個地方要提醒的是,就是最后要設置彈出窗體的顯示動畫,this.setanimationstyle(r.style.take_photo_anim); 這是必不可少的,只有加上了它,才能應用動畫效果!
看下take_photo_anim style的定義:

?
1
2
3
4
<style name="take_photo_anim" parent="android:animation">
    <item name="android:windowenteranimation">@anim/pop_enter_anim</item>
    <item name="android:windowexitanimation">@anim/pop_exit_anim</item>
</style>

就這么幾步,一個可以從屏幕底部滑動彈出的組件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public void showpopformbottom(view view) {
  takephotopopwin takephotopopwin = new takephotopopwin(this, onclicklistener);
  //showatlocation(view parent, int gravity, int x, int y)
  takephotopopwin.showatlocation(findviewbyid(r.id.main_view), gravity.center, 0, 0);
}
 
private view.onclicklistener onclicklistener = new view.onclicklistener() {
  @override
  public void onclick(view v) {
 
    switch (v.getid()) {
      case r.id.btn_take_photo:
        system.out.println("btn_take_photo");
        break;
      case r.id.btn_pick_photo:
        system.out.println("btn_pick_photo");
        break;
    }
  }
};

這下子,效果就和我一開始傳的圖一致啦!有木有學會了呢!?

拓展:
     玩過app的大家都知道,在你進入新頁面或者注冊登錄啥的時候,都會彈出一個等待的框框,表示網絡請求中,你需要耐心等待下,比如微信的等待請求框效果如下:

Android Animation實戰之屏幕底部彈出PopupWindow

    這里面其中也有個地方用到了動畫,那就是不停旋轉的那個小圖標,它其實用的就是旋轉動畫!
    關于如何實現這么樣一個旋轉等待框,我以前寫過一篇介紹的文章,可查看: 《android自定義progressdialog進度等待框》

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩高清一区 | 日日夜夜香蕉 | 成人午夜精品久久久久久久蜜臀 | 欧美一级播放 | 一区二区国产精品 | 国产精品日韩一区 | 午夜久久久 | av日韩在线播放 | 中文字幕一区二区三区不卡 | 国产精品99精品久久免费 | 天天色天天色 | 一级片一级片 | 久久精品一 | 亚洲精品一区在线观看 | 亚洲五码中文字幕 | 亚洲 精品 综合 精品 自拍 | 精品国产乱码久久久久久牛牛 | 国产精品美女在线观看 | 一级片在线观看网站 | 97伦理在线 | 伊人网在线 | 国产精品久久 | 国产在线视频网站 | 激情综合色综合久久综合 | 久久久精品| 国产精品成人一区二区 | 亚洲一区二区av | 国产日韩一级片 | 国产精品免费av | 久久人人爽爽爽人久久久 | 欧美日韩精品一区二区三区 | 国产精品一区二区视频 | 黄色毛片在线 | 欧美福利网址 | 国产黄色片免费观看 | 这里有精品视频 | 激情五月激情综合网 | 亚洲久久| 国产偷窥老熟盗摄视频 | 亚洲成av人片一区二区梦乃 | 久久久久久久久久久久福利 |