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

android 實現(xiàn)側(cè)邊彈窗特效代碼

 更新時間:2021年06月19日 14:33:10   作者:靈神翁  
側(cè)邊彈窗是在左邊,需要定位好位置,實現(xiàn)原理其實就是進出動效,用位移加透明度效果來控制,下面通過代碼給大家介紹android 實現(xiàn)側(cè)邊彈窗,需要的朋友參考下吧

大家好哇,又是我,夢辛工作室的靈,今天來給大家講解下如何實現(xiàn) 安卓的側(cè)邊彈窗,

先大概講下基本原理吧,其實很簡單,就是一個進出動效,用 位移 加 透明度 效果比較好,
比如你的側(cè)邊彈窗是在左邊,那就是從左往右位置 100%(代表動效目標的寬或高)
不過需要注意:
初始位置一定要先最后應該顯示的位置,不要將該View使用Margin或其他位移至其他位置,不然動效結(jié)束后,點擊視圖沒有響應,因為此時View還在初始位置,所以你點擊View僅動畫修改過后的位置是無效的,除非你使用的是屬性動畫
下面來看下我的布局,簡單寫了一個:

在這里插入圖片描述

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <RelativeLayout
        android:id="@+id/rel_dialog_back"
        android:background="#B3000000"
        android:layout_width="match_parent"
        android:layout_height="match_parent"  >


        <!-- 商品信息彈窗 -->
        <LinearLayout
            android:layout_alignParentRight="true"
            android:id="@+id/lin_dialog_content"
            android:layout_width="400dp"
            android:layout_height="match_parent"
            android:padding="10dp"
            android:background="#FFFFFF"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="我是彈窗"
                android:textColor="@color/colorAccent"
                android:gravity="center"
                android:textSize="80sp"
                android:layout_gravity="center"/>

        </LinearLayout>


    </RelativeLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

然后就是res/anim下寫動畫文件:
dialog_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/decelerate_interpolator">
    <!--透明度標簽:表示透明0到不透明1之間的變換-->
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0" >
    </alpha>
	<!-- 100% 代表向右 視圖寬度, 0%代表視圖初始位置 -->
   <translate
       android:fromXDelta="100%" 
       android:toXDelta="0%">
   </translate>

</set>

dialog_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/decelerate_interpolator">
    <!--透明度標簽:表示透明0到不透明1之間的變換-->
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0" >
    </alpha>

    <translate
        android:fromXDelta="0%"
        android:toXDelta="100%">
    </translate>

</set>

最后是代碼去觸發(fā)動畫:

final Animation anim = AnimationUtils.loadAnimation(this, R.anim.dialog_in);
        anim.setDuration(300);
        anim.setFillAfter(true);
        view.startAnimation(anim );

        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
            //一定要記得,動畫結(jié)束后清除動畫,然后及時View 處于 View.GONE狀態(tài)時也會觸發(fā)點擊兇過
                view.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

其實還可以進階一下,監(jiān)聽界面左邊部分的手勢,當按下點與抬起點之間的橫向距離達到一定值時啟動,入場動畫或者出場動畫,就可以達到通過手勢觸發(fā)或關(guān)閉側(cè)邊彈窗效果了,總體還是很簡單的,大家可以試試

以上就是android 實現(xiàn)側(cè)邊彈窗特效代碼的詳細內(nèi)容,更多關(guān)于android側(cè)邊彈窗的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Android從源碼的角度徹底理解事件分發(fā)機制的解析(下)

    Android從源碼的角度徹底理解事件分發(fā)機制的解析(下)

    這篇文章主要介紹了Android從源碼的角度徹底理解事件分發(fā)機制的解析(下),具有很好的參考價值,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • Android 給控件添加邊框陰影效果

    Android 給控件添加邊框陰影效果

    這篇文章主要介紹了Android 給控件添加邊框陰影效果,文中代碼部分top代表下邊的陰影高度,left代表右邊的陰影寬度。具體實例代碼大家參考下本文
    2017-11-11
  • Android 靜默方式實現(xiàn)批量安裝卸載應用程序的深入分析

    Android 靜默方式實現(xiàn)批量安裝卸載應用程序的深入分析

    本篇文章是對Android 靜默方式實現(xiàn)批量安裝卸載應用程序進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • Android消息個數(shù)提醒控件使用詳解

    Android消息個數(shù)提醒控件使用詳解

    這篇文章主要為大家詳細介紹了Android消息個數(shù)提醒控件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • android中px和dp,px和sp之間的轉(zhuǎn)換方法

    android中px和dp,px和sp之間的轉(zhuǎn)換方法

    在Android開發(fā)中dp和px,sp和px之間的轉(zhuǎn)換時必不可少的。下面腳本之家小編給大家?guī)砹薬ndroid中px和dp,px和sp之間的轉(zhuǎn)換方法,感興趣的朋友一起看看吧
    2018-06-06
  • Android?文件存儲系統(tǒng)原理

    Android?文件存儲系統(tǒng)原理

    這篇文章主要介紹了Android?文件存儲系統(tǒng)原理,Android?的文件系統(tǒng)類似于其他平臺的基于磁盤的文件系統(tǒng),包括好幾種類別具體詳情感興趣得朋友可以參考一下文章內(nèi)容
    2022-06-06
  • Android Studio多渠道打包套路

    Android Studio多渠道打包套路

    最近有好多朋友向小編咨詢Android Studio多渠道的打包方法,今天小編給大家分享Android Studio多渠道打包套路,需要的朋友參考下吧
    2017-11-11
  • 詳解android與服務(wù)端交互的兩種方式

    詳解android與服務(wù)端交互的兩種方式

    這篇文章主要介紹了詳解android與服務(wù)端交互的兩種方式,此處介紹兩種方式:使用Google原生的Gson解析json數(shù)據(jù),使用JSONObject解析json數(shù)據(jù),有興趣的可以了解一下
    2017-07-07
  • Android NavigationBar問題處理的方法

    Android NavigationBar問題處理的方法

    本篇文章主要介紹了Android NavigationBar問題處理的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • android多種滑動沖突的解決方案

    android多種滑動沖突的解決方案

    本篇文章主要介紹了android多種滑動沖突的解決方案,解決方案主要有2種,外部攔截法 和內(nèi)部攔截法,有興趣的可以了解一下。
    2017-02-02

最新評論