【android】add image in alertdialog
2011-12-23 17:17
155 查看
2011-08-28
my first android app---- 摇摇乐 第一版即将问世
这周总算做了点事情,为结果页增加了icon和pic
总结一下
问题: 为AlertDialog 增加图片,图片个数按照结果对象个数对应显示
查阅 AlertDialog sdk 发现比较好的方法是建立FrameLayout 然后在里边增加imageview,最后 set 到 dialog属性里
但 FrameLayout 怎么建立,费了一些周折才弄出来,不能在同一个activity的layout里增加framelayout
会出现the specified child all ready has a parent 这样的错误
需要新建个 propalterdialog.xml 单独定义并安放layout,再调用 LayoutInflater 将这个布局换到当前layout里显示
FrameLayout的xml里可以什么不定义ImageView标签
用framelayout的上下文 动态生成image
但出现个问题 framelayout里的图片会重叠,使用 LinearLayout则正常 xml里设置 android:orientation="horizontal" 按行去布局,将图片放在一行
以下是用到的所有代码
my first android app---- 摇摇乐 第一版即将问世
这周总算做了点事情,为结果页增加了icon和pic
总结一下
问题: 为AlertDialog 增加图片,图片个数按照结果对象个数对应显示
查阅 AlertDialog sdk 发现比较好的方法是建立FrameLayout 然后在里边增加imageview,最后 set 到 dialog属性里
但 FrameLayout 怎么建立,费了一些周折才弄出来,不能在同一个activity的layout里增加framelayout
会出现the specified child all ready has a parent 这样的错误
需要新建个 propalterdialog.xml 单独定义并安放layout,再调用 LayoutInflater 将这个布局换到当前layout里显示
FrameLayout的xml里可以什么不定义ImageView标签
用framelayout的上下文 动态生成image
但出现个问题 framelayout里的图片会重叠,使用 LinearLayout则正常 xml里设置 android:orientation="horizontal" 按行去布局,将图片放在一行
以下是用到的所有代码
LayoutInflater factory = LayoutInflater.from(DemoActivity.this); LinearLayout fl = (LinearLayout) factory.inflate(R.layout.propalterdialog,null); int size = selectionList.size(); for(Selection sel:selectionList){ ImageView imageView = new ImageView(fl.getContext()); imageView.setLayoutParams(new FrameLayout.LayoutParams(190/size, 190/size, 100)); int image_id = DemoActivity.this.getResources().getIdentifier(sel.getPicture(), "drawable", "com.netqin.android.lab"); imageView.setImageResource(image_id); fl.addView(imageView); } new AlertDialog.Builder(DemoActivity.this).setTitle("result") .setIcon(R.drawable.result_icon) .setView(fl) .setMessage(result).setPositiveButton("ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); }
相关文章推荐
- How to use AlertDialog.Builder in Android applications
- android使用AlertDialog提示 Unable to add window -- token null is not for an application的解决方案
- android AlertDialog显示错误 Unable to add window token null is not for an application
- 关于android创建对话框报错The method setPositiveButton(int, DialogInterface.OnClickListener) in the type Alert
- AlertDialog.Builder发生:android.view.WindowManager$BadTokenException: Unable to add window
- android AlertDialog显示错误 Unable to add window token null is not for an application解决办法
- 关于android创建对话框报错The method setPositiveButton(int, DialogInterface.OnClickListener) in the type Alert
- Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)
- Android中的对话框AlertDialog使用技巧合集
- android AlertDialog
- Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)
- AlertDialog显示错误 Unable to add window token null is not for an application
- android-如何关闭AlertDialog.Builder对话框
- Android之对话框AlertDialog及其子类的介绍(一)
- Android中利用反射机制来控制AlertDialog窗口不被关闭
- ERROR: Failure processing PNG image in Android
- androids-addjavascriptinterface-equivalent-in-ios
- Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)
- Android service里面启动activity和alertdialog .
- Android AlertDialog 方法setView(view,0,0,0,0)开发自定义对话框