【android】自定义全屏dialog显示+listview
2016-09-09 18:20
423 查看
折腾半天,自定义全屏dialog,单对话框式。
存一下,日后不用再写了。
以上是正经的对话框。只包含一个listview和一个imageview,imageview做了旋转效果。listview用于增添数据。
dialog布局:
背景制定了半透明。include里是一个旋转的imageview,没什么实际作用。
之前脑抽了一下,想做旋转的时候一直在考虑怎么加个独立的线程调用实现旋转……后来一想android提供了啊……
对话框的dialog。我的需求是半透明,全屏。翻了不少博客。最终用这个实现成功……
主活动调用,传各种参数。
要增加数据时候直接add就行了。
存一下,日后不用再写了。
/** * 基础语音对话框 * @author make * */ public class BaseVoiceDialog { private Context context; private boolean show = false; private int height; private int width; //初始化 private ListView listView; private Dialog dialog;//弹出的dialog private ImageView imageView_animate; //private LayoutParams lay = dialog; private ArrayAdapter adapter; /** * 初始化传参。 * @param context * @param height * @param width */ public BaseVoiceDialog(Context context,int height,int width){ this.height = height; this.width = width; this.context = context; dialog = new Dialog(context,R.style.CustomDialog); dialog.setContentView(R.layout.dialog_communicate); dialog.setCancelable(true); initView();//初始化视图 } //初始化方法 private void initView(){ //初始化控件 listView = (ListView) dialog.findViewById(R.id.listview); imageView_animate = (ImageView) dialog.findViewById(R.id.imageview_animate); //初始化adapter adapter = new ArrayAdapter(context, R.layout.item_communicate_right,R.id.textView_communicate); listView.setAdapter(adapter); //控件参数设置 LayoutParams lay = dialog.getWindow().getAttributes(); lay.height = height; lay.width = width; //旋转动画设置 Animation operatingAnim = AnimationUtils.loadAnimation(context, R.anim.rotate); LinearInterpolator lin = new LinearInterpolator(); operatingAnim.setInterpolator(lin); imageView_animate.startAnimation(operatingAnim); } /** * 增加数据方法 * @param data */ public void addData(String data){ adapter.add(data); adapter.notifyDataSetChanged(); } public void showDialog(){ show = true; dialog.show(); } public void closeDialog(){ show = false; dialog.dismiss(); } public boolean isShowing(){ return show; }
以上是正经的对话框。只包含一个listview和一个imageview,imageview做了旋转效果。listview用于增添数据。
dialog布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#b0000000" android:gravity="bottom" > <include android:id="@+id/include_communicate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="20dp" layout="@layout/view_thread_communicate_button" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_margin="20dp" android:layout_above="@id/include_communicate" android:background="#00000000" > <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="#00000000" android:dividerHeight="2dp" android:background="#00000000" ></ListView> </LinearLayout> </RelativeLayout>
背景制定了半透明。include里是一个旋转的imageview,没什么实际作用。
之前脑抽了一下,想做旋转的时候一直在考虑怎么加个独立的线程调用实现旋转……后来一想android提供了啊……
对话框的dialog。我的需求是半透明,全屏。翻了不少博客。最终用这个实现成功……
<style name="CustomDialog" parent="android:style/Theme.Dialog"> <item name="android:windowFullscreen">true</item> <!--全屏显示--> <item name="android:windowFrame">@null</item><!--边框--> <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上--> <item name="android:windowIsTranslucent">false</item><!--半透明--> <item name="android:windowNoTitle">true</item><!--无标题--> <item name="android:windowBackground">@color/transparent</item><!--背景透明--> <item name="android:backgroundDimEnabled">false</item><!--模糊--> </style>
private void initDialog(){ DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); Rect rect = new Rect(); View view = getWindow().getDecorView(); view.getWindowVisibleDisplayFrame(rect); int height = dm.heightPixels; int width = dm.widthPixels; baseVoiceDialog = new BaseVoiceDialog(this,height,width); baseVoiceDialog.showDialog(); }
主活动调用,传各种参数。
要增加数据时候直接add就行了。
相关文章推荐
- Android自定义Dialog布局listview 实现显示安装的应用
- android如何设置全屏的DialogFragment以及自定义提示框支持横竖屏显示
- android 设置自定义dialog全屏显示
- Android ListView的滚动条始终显示并且滚动条样式自定义
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- 一步一步学android之控件篇——ListView自定义显示数据格式
- Android ListView的滚动条始终显示并且滚动条样式自定义
- 自定义dialog包含一个显示图片的listview
- Android AlertDialog全屏显示去除白色边框
- 实现自定义view(2):仿Android QQ多屏幕显示ListView的效果
- 自定义dialog包含一个显示图片的listview
- android最简单的自定义全屏Dialog
- android 自定义Dialog背景透明及显示位置设置
- Android得到系统已安装应用程序包列表方法 自定义ListView显示 PackageManager的使用
- Android开发:setContentView切换界面,自定义带CheckBox的ListView显示SQlite条目-----实现
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置(转载)
- Android中ListView的自定义显示