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

Android自定義PopWindow帶動畫向下彈出效果

 更新時間:2021年09月09日 14:19:21   作者:獄火蒼穹  
這篇文章主要為大家詳細介紹了Android自定義PopWindow帶動畫向下彈出效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

首先建一個popwin的實體類

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è)置外部可點擊
  this.setOutsideTouchable(true);
  /* 設(shè)置彈出窗口特征 */
  // 設(shè)置視圖
  this.setContentView(this.view);
  // 設(shè)置彈出窗體的寬和高
  this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);//高
  this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);//寬

  // 設(shè)置彈出窗體可點擊
  this.setFocusable(true);

  // 設(shè)置彈出窗體顯示時的動畫,從底部向上彈出
  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表示手指點擊的位置,屏幕頂端為0,往下一次遞增。height是popwin的高度。y > height就表示手指點在popwin的外面,然后關(guān)閉popwin
     if (y > height) {
      dismiss();
     }
    }
    return true;
   }

  });

 }

}

然后是這個類的布局 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="移動靜態(tài)"
   android:textColor="#f123" />

 </LinearLayout>
</LinearLayout>

接下來是這個類里涉及的動畫 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>

然后是進場動畫 pop_enter_anim和出場動畫 pop_exit_anim,在res下建一個文件夾anim,分別新建上面兩個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">
 <!-- 平移動畫 -->
 <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">
 <!-- 平移動畫 -->
 <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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android中解決RecyclerView各種點擊事件的方法

    Android中解決RecyclerView各種點擊事件的方法

    這篇文章主要介紹了Android中解決RecyclerView各種點擊事件的方法,完美解決RecyclerView點擊事件、長按事件、子項點擊事件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android 橫豎屏處理的知識小結(jié)

    Android 橫豎屏處理的知識小結(jié)

    這篇文章主要介紹了Android 橫豎屏處理的知識小結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03
  • Android Handler中的休眠喚醒實現(xiàn)詳解

    Android Handler中的休眠喚醒實現(xiàn)詳解

    這篇文章主要為大家介紹了Android Handler中的休眠喚醒實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • 詳解Android如何設(shè)計一個全局可調(diào)用的ViewModel對象

    詳解Android如何設(shè)計一個全局可調(diào)用的ViewModel對象

    很多時候我們需要維護一個全局可用的ViewModel,因為這樣可以維護全局同一份數(shù)據(jù)源,且方便使用協(xié)程綁定App的生命周期,那如何設(shè)計全局可用的ViewModel對象,文中介紹的非常詳細,需要的朋友可以參考下
    2023-05-05
  • android中在Activity中響應(yīng)ListView內(nèi)部按鈕的點擊事件的兩種方法

    android中在Activity中響應(yīng)ListView內(nèi)部按鈕的點擊事件的兩種方法

    本篇文章主要介紹了android中在Activity中響應(yīng)ListView內(nèi)部按鈕的點擊事件的兩種方法,有需要的可以了解一下。
    2016-11-11
  • Android入門:多線程斷點下載詳細介紹

    Android入門:多線程斷點下載詳細介紹

    本篇文章主要介紹了 Android多線程斷點下載,即文件在下載一部分中斷后,可繼續(xù)接著已有進度下載,有需要的可以了解一下。
    2016-11-11
  • Android實現(xiàn)圖片滾動效果

    Android實現(xiàn)圖片滾動效果

    這篇文章主要為大家詳細介紹了Android實現(xiàn)圖片滾動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • Android ViewPager中顯示圖片與播放視頻的填坑記錄

    Android ViewPager中顯示圖片與播放視頻的填坑記錄

    這篇文章主要給介紹了關(guān)于Android ViewPager中顯示圖片與播放視頻的一些填坑記錄,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-05-05
  • Android自定義實現(xiàn)轉(zhuǎn)盤菜單

    Android自定義實現(xiàn)轉(zhuǎn)盤菜單

    旋轉(zhuǎn)菜單是一種占用空間較大,實用性稍弱的UI,本文主要為大家詳細介紹了Android如何自定義實現(xiàn)轉(zhuǎn)盤菜單,文中的示例代碼講解詳細,有需要的小伙伴可以參考下
    2023-12-12
  • 為什么不要在?Flutter?中使用全局變量

    為什么不要在?Flutter?中使用全局變量

    這篇文章主要介紹了為什么不要在Flutter中使用全局變量,全局變量是公共變量,可以被Flutter程序中的每個方法和對象訪問,全局變量是局部變量的替代品,它們在方法中創(chuàng)建并在該方法中訪問
    2022-08-08

最新評論

益阳市| 清流县| 东辽县| 开江县| 广平县| 华亭县| 朝阳县| 巧家县| 绥芬河市| 延吉市| 普兰县| 滨州市| 怀集县| 会宁县| 天津市| 乌海市| 惠安县| 皋兰县| 临沂市| 高州市| 穆棱市| 宝鸡市| 木兰县| 舟曲县| 得荣县| 哈密市| 晋江市| 新干县| 淅川县| 建水县| 盐池县| 邯郸市| 新巴尔虎左旗| 潼南县| 沐川县| 张北县| 温泉县| 浑源县| 灌阳县| 土默特右旗| 北安市|