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);
//初始化控件
//將布局設(shè)置給Dialog
dialog.setContentView(inflate);
//獲取當(dāng)前Activity所在的窗體
Window dialogWindow = dialog.getWindow();
//設(shè)置Dialog從窗體底部彈出
dialogWindow.setGravity( Gravity.BOTTOM);
//獲得窗體的屬性
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.y = 20;//設(shè)置Dialog距離底部的距離
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
// 將屬性設(shè)置給窗體
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> <!-- 無標(biāo)題 --> <item name="android:windowNoTitle">true</item> <!-- 半透明 --> <item name="android:windowIsTranslucent">true</item> <!-- Dialog進(jìn)入及退出動畫 --> <item name="android:windowAnimationStyle">@style/ActionSheetDialogAnimation</item> </style> <!-- ActionSheet進(jìn)出動畫 --> <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>
進(jìn)入動畫(左下角開始放大):
<?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)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- Android 全局Dialog的簡單實現(xiàn)方法
- Android使用Dialog風(fēng)格彈出框的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懸浮窗彈出
相關(guān)文章
Android判斷11位手機號碼的方法(正則表達(dá)式)
項目里頭需要做一個判斷用戶輸入的號碼是否是正確的手機號碼,正確的手機號碼應(yīng)該是11位的,這里我們需要用一個正則表達(dá)式來進(jìn)行判斷,下面我把寫法分享給大家2016-12-12
Android的權(quán)限設(shè)置及自啟動設(shè)置方法
今天小編就為大家分享一篇Android的權(quán)限設(shè)置及自啟動設(shè)置方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07
Android中使用ContentProvider管理系統(tǒng)資源的實例
這篇文章主要介紹了Android中使用ContentProvider管理系統(tǒng)資源的實例,講解了ContentProvider對系統(tǒng)中聯(lián)系人及多媒體資源的管理例子,需要的朋友可以參考下2016-04-04
Android WebView實現(xiàn)長按保存圖片及長按識別二維碼功能
本文要使用Android WebView實現(xiàn)長按保存圖片及長按識別二維碼功能,當(dāng)用戶在瀏覽網(wǎng)頁的時候,長按某一區(qū)域,識別如果是圖片,則彈出彈框,出現(xiàn)保存圖片的功能2018-01-01
Android程序開發(fā)之Fragment實現(xiàn)底部導(dǎo)航欄實例代碼
流行的應(yīng)用的導(dǎo)航一般分為兩種,一種是底部導(dǎo)航,一種是側(cè)邊欄。本文給大家介紹Fragment實現(xiàn)底部導(dǎo)航欄,對Fragment實現(xiàn)底部導(dǎo)航欄相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2016-03-03

