android 项目需求,底部需要弹出list框,整理了一个很好用的Dialog。代码如下:

   1.代码片段

private Context mContext;private Dialog bottomDialog;private ViewHolder holder;

private void showDialog() {        bottomDialog = new Dialog(mContext, R.style.BottomDialog);        View contentView = LayoutInflater.from(mContext).inflate(R.layout.evaluation_historical_dialog, null);        bottomDialog.setContentView(contentView);        ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();         
        //这里使用getResources方法,获取屏幕的分辨率,高度占屏幕的二分之一
        layoutParams.width = getResources().getDisplayMetrics().widthPixels;        layoutParams.height = getResources().getDisplayMetrics().heightPixels / 2;        contentView.setLayoutParams(layoutParams);        bottomDialog.getWindow().setGravity(Gravity.BOTTOM);        bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);        bottomDialog.show();        holder = new ViewHolder();       
      holder.xsnr = (TextView) contentView.findViewById(R.id.xsnr);
      holder.xsnr.setText("admin");
}
class ViewHolder {    private TextView xsnr;}
   

styles.xml 文件


color.xml 文件

name="text_white">#ffffff
anim 文件:弹出动画效果

1.tranlate_dialog_in.xml
<?xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="300"    android:fromXDelta="0"    android:fromYDelta="100%"    android:toXDelta="0"    android:toYDelta="0">
2.tranlate_dialog_out.xml
<?xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android"  android:duration="300"  android:fromXDelta="0"  android:fromYDelta="0"  android:toXDelta="0"  android:toYDelta="100%"> 
3.布局文件
evaluation_historical_dialog.xml
   
<?xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent
    android:orientation="vertical">
                  android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal"        android:padding="2dp">                    android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="5dp"            android:layout_marginTop="10dp"            android:layout_weight="1"            android:padding="5dp"            android:text="巡视内容:" />                    android:id="@+id/xsnr"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="5dp"            android:layout_marginTop="10dp"            android:layout_weight="1"            android:padding="5dp"            android:text="巡视内容" />     

最后大功告成,这个evaluation_historical_dialog.xml是自定义的,可以根据自己的需求来改写。

最后说两点:

1.在你需要调用的地方直接调用showDialog()这个方法就可以了。

2.取消直接用 bottomDialog.dismiss();



   
   

更多相关文章

  1. android 读取doc文档
  2. Android(安卓)JNI 编程常见小问题
  3. android模拟器分辨率设置以及获得模拟器分辨率代码片段
  4. Android.mk 代码注释
  5. 关于Android中res等几种文件通过InputStream方式读入工程中
  6. Android(安卓)批量卸载手机上的apk
  7. android常见问题记录(03.13update)
  8. 使用 adb 命令向 Android(安卓)发送广播
  9. android中SharedPerferences保存数据

随机推荐

  1. Android(安卓)Push
  2. android UI进阶之弹窗的使用(2)--实现通讯
  3. Android配置build.gradle自动化编译signi
  4. Android(安卓)核心分析 之五 -----基本空
  5. android知识链接汇总(2)
  6. android:paddingLeft与android:layout_ma
  7. Android(安卓)MediaPlayer+SurfaceView播
  8. Android最新获取oaid的方法及sdk
  9. android通知栏进度条
  10. android:minSdkVersion 之我见