欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

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)畫(huà),從底部向上彈出
  this.setAnimationStyle(R.style.take_photo_anim);
//  mMenuView添加OnTouchListener監(jiān)聽(tīng)判斷獲取觸屏位置如果在選擇框外面則銷(xiāo)毀彈出框
  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è)類(lèi)的布局 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>

接下來(lái)是這個(gè)類(lèi)里涉及的動(dòng)畫(huà) 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)場(chǎng)動(dòng)畫(huà) pop_enter_anim和出場(chǎng)動(dòng)畫(huà) 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)畫(huà) -->
 <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)畫(huà) -->
 <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)聽(tīng)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);
  }
});

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

相關(guān)文章

  • Android獲取雙卡雙待手機(jī)的SIM卡信息示例代碼

    Android獲取雙卡雙待手機(jī)的SIM卡信息示例代碼

    這篇文章主要給大家介紹了關(guān)于Android獲取雙卡雙待手機(jī)的SIM卡信息的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位Android開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • android通過(guò)配置文件設(shè)置應(yīng)用安裝到SD卡上的方法

    android通過(guò)配置文件設(shè)置應(yīng)用安裝到SD卡上的方法

    在AndroidManifest.xml文件的manifest里面加上一句話,就可以把應(yīng)用安裝到SD卡上
    2013-11-11
  • 一個(gè)Activity中多個(gè)Fragment的切換

    一個(gè)Activity中多個(gè)Fragment的切換

    經(jīng)常會(huì)遇到在一個(gè)activity界面上布局多個(gè)fragment,但是如何從一個(gè)fragment跳轉(zhuǎn)到另一個(gè)fragment呢?本文主要對(duì)一個(gè)Activity中多個(gè)Fragment的切換進(jìn)行介紹,下面跟著小編一起來(lái)看下吧
    2017-01-01
  • Android仿知乎日?qǐng)?bào)開(kāi)屏頁(yè)效果

    Android仿知乎日?qǐng)?bào)開(kāi)屏頁(yè)效果

    這篇文章主要為大家詳細(xì)介紹了Android仿知乎日?qǐng)?bào)開(kāi)屏頁(yè)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • 總結(jié)安卓(Android)中常用的跳轉(zhuǎn)工具

    總結(jié)安卓(Android)中常用的跳轉(zhuǎn)工具

    在大家日常開(kāi)發(fā)的時(shí)候經(jīng)常會(huì)用到各式各樣的跳轉(zhuǎn),如跳轉(zhuǎn)到QQ、微信聊天界面、跳轉(zhuǎn)到聯(lián)系人界面或者跳轉(zhuǎn)到瀏覽器和照相機(jī)等等之類(lèi)的,本文將常用到的一些跳轉(zhuǎn)集合到一起,這樣更方便大家以后使用,有需要的小伙伴們可以參考借鑒。
    2016-08-08
  • 花樣使用Handler與源碼分析

    花樣使用Handler與源碼分析

    今天小編就為大家分享一篇關(guān)于花樣使用Handler與源碼分析,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-01-01
  • Android實(shí)戰(zhàn)教程第一篇之最簡(jiǎn)單的計(jì)算器

    Android實(shí)戰(zhàn)教程第一篇之最簡(jiǎn)單的計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)戰(zhàn)教程第一篇,如何實(shí)現(xiàn)最簡(jiǎn)單的計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android自定義控件之可拖動(dòng)控制的圓環(huán)控制條實(shí)例代碼

    Android自定義控件之可拖動(dòng)控制的圓環(huán)控制條實(shí)例代碼

    這篇文章主要介紹了Android自定義控件之可拖動(dòng)控制的圓環(huán)控制條實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-04-04
  • Android Zxing 轉(zhuǎn)換豎屏掃描且提高識(shí)別率的方法

    Android Zxing 轉(zhuǎn)換豎屏掃描且提高識(shí)別率的方法

    本篇文章主要介紹了Android Zxing 轉(zhuǎn)換豎屏掃描且提高識(shí)別率的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Android 8.0系統(tǒng)中應(yīng)用圖標(biāo)的適配技巧

    Android 8.0系統(tǒng)中應(yīng)用圖標(biāo)的適配技巧

    今天小編就為大家分享一篇關(guān)于Android 8.0系統(tǒng)中應(yīng)用圖標(biāo)的適配技巧,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2018-10-10

最新評(píng)論