今天将仿抖音注册界面完成后接着便将注册界面实现了,这里利用的是Dialog实现的
接下来介绍如何实现底部弹出Dialog
1.首先编写动画文件
<!--tranlate_dialog_in.xml-->
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXDelta="0"
android:fromYDelta="100%"
android:toXDelta="0"
android:toYDelta="0">
</translate>
<!--tranlate_dialog_out.xml-->
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="100%">
</translate>
2.编写Dialog的style
<style name="BottomDialog" parent="@style/Base.V7.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="BottomDialog.Animation" parent="Animation.AppCompat.Dialog">
<item name="android:windowEnterAnimation">@anim/tranlate_dialog_in</item>
<item name="android:windowExitAnimation">@anim/tranlate_dialog_out</item>
</style>
3.代码中实现
Dialog bottomDialog = new Dialog(context, R.style.BottomDialog);
bottomDialog.setContentView(contentView);
ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
layoutParams.width = context.getResources().getDisplayMetrics().widthPixels;
layoutParams.height=context.getResources().getDisplayMetrics().heightPixels;
contentView.setLayoutParams(layoutParams);
bottomDialog.getWindow().setGravity(Gravity.BOTTOM);
bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
bottomDialog.show();