典型的看图
布局:
样式:
两个动画文件:
push_bottom_in.xml
push_bottom_out.xml
http://blog.csdn.net/wangkeke1860/article/details/46488285
http://blog.csdn.net/wangkeke1860/article/details/46497307
import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.Gravity; import android.view.View; import android.view.Window; import android.view.WindowManager; import cn.tangdada.tangbang.R; public class SimpleBottomDialog extends Dialog { private Context context; public SimpleBottomDialog(Context context) { this(context, R.style.Theme_Dialog_From_Bottom); // TODO Auto-generated constructor stub } public SimpleBottomDialog(Context context, int theme) { super(context, theme); // TODO Auto-generated constructor stub this.context = context; init(); } private void init() { this.setCanceledOnTouchOutside(true); this.setCancelable(true); } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.dialog_simple_bottom); initViews(); initValues(); } private void initViews() { findViewById(R.id.btn_0).setOnClickListener(clickListener); findViewById(R.id.btn_1).setOnClickListener(clickListener); } private void initValues() { // 不能写在init()中 Window window = getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); DisplayMetrics dm = context.getResources().getDisplayMetrics(); lp.width = dm.widthPixels;//让dialog的宽占满屏幕的宽 lp.gravity = Gravity.BOTTOM;//出现在底部 window.setAttributes(lp); } View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_0: if (onOKClickListener != null) { onOKClickListener.onOKClick(v); } dismiss(); break; case R.id.btn_1: dismiss(); break; default: break; } } }; private OnOKClickListener onOKClickListener; public interface OnOKClickListener { public void onOKClick(View v); } public void setOnOKClickListener(OnOKClickListener onOKClickListener) { this.onOKClickListener = onOKClickListener; } }
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="vertical" android:padding="@dimen/padding" > <Button android:id="@+id/btn_0" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin" android:background="@drawable/bg_btn_white_blue_with_corner" android:padding="@dimen/padding" android:text="@string/send" /> <Button android:id="@+id/btn_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bg_btn_white_blue_with_corner" android:padding="@dimen/padding" android:text="@string/cancel" /> </LinearLayout>
样式:
<style name="Theme_Dialog_From_Bottom" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@style/dialog_animation</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:windowBackground">@android:color/transparent</item> </style> <style name="dialog_animation" parent="@android:style/Animation.Dialog"> <item name="android:windowEnterAnimation">@anim/push_bottom_in</item> <item name="android:windowExitAnimation">@anim/push_bottom_out</item> </style>
两个动画文件:
push_bottom_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="400" android:fromYDelta="100%p" android:toYDelta="0" /> <alpha android:duration="400" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set>
push_bottom_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="400" android:fromYDelta="0" android:toYDelta="50%p" /> <alpha android:duration="400" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set>
http://blog.csdn.net/wangkeke1860/article/details/46488285
http://blog.csdn.net/wangkeke1860/article/details/46497307