a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

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

Android自定義PopWindow帶動(dòng)畫向下彈出效果

2019-10-21 21:34:45
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了PopWindow實(shí)現(xiàn)帶動(dòng)畫向下彈出效果的具體代碼,供大家參考,具體內(nèi)容如下

首先建一個(gè)popwin的實(shí)體類

package dmpte.mytest;import android.content.Context;import android.view.LayoutInflater;import android.view.MotionEvent;import android.view.View;import android.widget.PopupWindow;import android.widget.RelativeLayout;public class PopWin extends PopupWindow { private Context mContext; private View view; public PopWin(final Context mContext, View.OnClickListener itemsOnClick, int flag) {  this.mContext = mContext;  this.view = LayoutInflater.from(mContext).inflate(R.layout.view_popwin, null);  // 設(shè)置外部可點(diǎn)擊  this.setOutsideTouchable(true);  /* 設(shè)置彈出窗口特征 */  // 設(shè)置視圖  this.setContentView(this.view);  // 設(shè)置彈出窗體的寬和高  this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);//高  this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);//寬  // 設(shè)置彈出窗體可點(diǎn)擊  this.setFocusable(true);  // 設(shè)置彈出窗體顯示時(shí)的動(dòng)畫,從底部向上彈出  this.setAnimationStyle(R.style.take_photo_anim);//  mMenuView添加OnTouchListener監(jiān)聽判斷獲取觸屏位置如果在選擇框外面則銷毀彈出框  this.view.setOnTouchListener(new View.OnTouchListener() {   @Override   public boolean onTouch(View v, MotionEvent event) {    int height = view.findViewById(R.id.pop_layout).getHeight();    int y = (int) event.getY();    if (event.getAction() == MotionEvent.ACTION_DOWN) {    //Y表示手指點(diǎn)擊的位置,屏幕頂端為0,往下一次遞增。height是popwin的高度。y > height就表示手指點(diǎn)在popwin的外面,然后關(guān)閉popwin     if (y > height) {      dismiss();     }    }    return true;   }  }); }}

然后是這個(gè)類的布局 view_popwin.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pop_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@null" android:orientation="vertical"> <LinearLayout  android:layout_width="match_parent"  android:layout_height="170dp"  android:background="#ffff"  android:orientation="vertical">  <TextView   android:id="@+id/tv_jingtai"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_gravity="center"   android:layout_marginTop="2dp"   android:gravity="center"   android:text="移動(dòng)靜態(tài)"   android:textColor="#f123" /> </LinearLayout></LinearLayout>

接下來是這個(gè)類里涉及的動(dòng)畫 popwin_anim,在res/values/styles下

<style name="popwin_anim" parent="android:Animation">    <item name="android:windowEnterAnimation">@anim/pop_enter_anim</item>    <item name="android:windowExitAnimation">@anim/pop_exit_anim</item></style>

然后是進(jìn)場動(dòng)畫 pop_enter_anim和出場動(dòng)畫 pop_exit_anim,在res下建一個(gè)文件夾anim,分別新建上面兩個(gè)xml

pop_enter_anim.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <!-- 平移動(dòng)畫 --> <translate  android:duration="500"  android:fromYDelta="-100%p"  android:toYDelta="0" /></set>

pop_exit_anim.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <!-- 平移動(dòng)畫 --> <translate  android:duration="1000"  android:fromYDelta="0"  android:toYDelta="-100%p" /></set>

最后是使用

//讓背景變暗 WindowManager.LayoutParams lp = getWindow().getAttributes();    lp.alpha = 0.7f;    getWindow().setAttributes(lp);    //彈出窗體    PopWin popWin_ = new PopWin(this, null, 0);    popWin_.showAsDropDown(findViewById(R.id.relativeLayout));    //監(jiān)聽popwin是否關(guān)閉,關(guān)閉的話讓背景恢復(fù)    popWin_.setOnDismissListener(new PopupWindow.OnDismissListener() {     @Override     public void onDismiss() {      WindowManager.LayoutParams lp = getWindow().getAttributes();      lp.alpha = 1f;      getWindow().setAttributes(lp);  }});

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


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 日本高清一二三 | 一本色道久久综合狠狠躁篇的优点 | 成人国产精品久久久 | 欧美视频一区二区 | 日韩欧美一级在线 | 高清精品一区二区 | 男女www视频 | 青青成人网 | 国产精品一区二区三 | 欧美成人免费在线观看 | 一级毛片视频播放 | 亚洲精品国产成人 | av免费网站在线观看 | 91性高湖久久久久久久久_久久99 | 欧美成人一区二区 | 特级毛片在线大全免费播放 | 国产成人精品在线 | 日韩精品一区二区三区老鸭窝 | 毛片天堂 | 日韩精品视频免费专区在线播放 | 亚洲欧美日韩在线 | 国产精品久久一区 | 欧美日韩久久久久 | 成年人免费在线视频 | 欧美日韩91| 欧美高清在线观看 | 可以看黄的视频 | 一级免费毛片 | 国产精品久久久久久久久久久久 | 日本二区在线播放 | 九九小视频 | 麻豆高清免费国产一区 | 国产精品日韩专区 | 超碰人人在线 | 看久久毛片 | 久久艹精品视频 | 成人久久18免费观看 | 日韩中文视频 | 日韩精品一区二区三区在线观看 | 国产精品揄拍一区二区久久国内亚洲精 | 极品美女一线天 |