Android 中從屏幕左下角彈出Dialog動畫效果的實現(xiàn)代碼
更新時間:2016年12月27日 14:05:34 作者:coder_Bai
這篇文章主要介紹了Android 中從屏幕左下角彈出Dialog動畫效果的實現(xiàn)代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
MainActivity代碼:
import android.app.Dialog; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.Window; import android.view.WindowManager; public class MainActivity extends AppCompatActivity { private View inflate; private Dialog dialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View view) { dialog = new Dialog(this,R.style.ActionDialogStyle); //填充對話框的布局 inflate = LayoutInflater.from(this).inflate(R.layout.item_dialog, null); //初始化控件 //將布局設置給Dialog dialog.setContentView(inflate); //獲取當前Activity所在的窗體 Window dialogWindow = dialog.getWindow(); //設置Dialog從窗體底部彈出 dialogWindow.setGravity( Gravity.BOTTOM); //獲得窗體的屬性 WindowManager.LayoutParams lp = dialogWindow.getAttributes(); lp.y = 20;//設置Dialog距離底部的距離 lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 將屬性設置給窗體 dialogWindow.setAttributes(lp); dialog.show();//顯示對話框 } }
主界面的布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="ucai.cn.dialoganimator.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:onClick="click"/> </LinearLayout>
Dialog布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/hani_gift_1" android:layout_gravity="center"/> </LinearLayout>
styles代碼:
<style name="ActionDialogStyle" parent="@android:style/Theme.Dialog">
<!-- 背景透明 --> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowContentOverlay">@null</item> <!-- 浮于Activity之上 --> <item name="android:windowIsFloating">true</item> <!-- 邊框 --> <item name="android:windowFrame">@null</item> <!-- Dialog以外的區(qū)域模糊效果 --> <item name="android:backgroundDimEnabled">true</item> <!-- 無標題 --> <item name="android:windowNoTitle">true</item> <!-- 半透明 --> <item name="android:windowIsTranslucent">true</item> <!-- Dialog進入及退出動畫 --> <item name="android:windowAnimationStyle">@style/ActionSheetDialogAnimation</item> </style> <!-- ActionSheet進出動畫 --> <style name="ActionSheetDialogAnimation" parent="@android:style/Animation.Dialog"> <item name="android:windowEnterAnimation">@anim/actionsheet_dialog_in</item> <item name="android:windowExitAnimation">@anim/actionsheet_dialog_out</item> </style>
進入動畫(左下角開始放大):
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXScale="0" android:toXScale="100%" android:fromYScale="0" android:toYScale="100%" android:pivotX="0%" android:pivotY="100%" />
退出動畫(向下移動):
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:fromYDelta="0" android:toYDelta="100%" />
以上所述是小編給大家介紹的Android 中從屏幕左下角彈出Dialog動畫效果的實現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
您可能感興趣的文章:
- Android 全局Dialog的簡單實現(xiàn)方法
- Android使用Dialog風格彈出框的Activity
- Android實現(xiàn)從底部彈出的Dialog示例(一)
- Android中自定義的dialog中的EditText無法彈出輸入法解決方案
- Android 仿蘋果底部彈出Dialog
- Android 從底部彈出Dialog(橫向滿屏)的實例代碼
- Android解決dialog彈出時無法捕捉Activity的back事件的方法
- Android自定義彈出框dialog效果
- Android 解決dialog彈出時無法捕捉Activity的back事件問題
- Android 8.0如何完美適配全局dialog懸浮窗彈出
相關文章
Android中使用ContentProvider管理系統(tǒng)資源的實例
這篇文章主要介紹了Android中使用ContentProvider管理系統(tǒng)資源的實例,講解了ContentProvider對系統(tǒng)中聯(lián)系人及多媒體資源的管理例子,需要的朋友可以參考下2016-04-04Android WebView實現(xiàn)長按保存圖片及長按識別二維碼功能
本文要使用Android WebView實現(xiàn)長按保存圖片及長按識別二維碼功能,當用戶在瀏覽網(wǎng)頁的時候,長按某一區(qū)域,識別如果是圖片,則彈出彈框,出現(xiàn)保存圖片的功能2018-01-01Android程序開發(fā)之Fragment實現(xiàn)底部導航欄實例代碼
流行的應用的導航一般分為兩種,一種是底部導航,一種是側(cè)邊欄。本文給大家介紹Fragment實現(xiàn)底部導航欄,對Fragment實現(xiàn)底部導航欄相關知識感興趣的朋友一起學習吧2016-03-03