`
fonter
  • 浏览: 857950 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Android AlertDialog动态添加组件和padding靠边问题

阅读更多

先上图

 

 

 

AlertDialog有个问题是动态添加组件时,组件会很靠边框,这样很不好看,下面这个方案是解决这个问题

 

 

		LayoutInflater mInflater = (LayoutInflater) getContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = mInflater.inflate(R.layout.recordlayout, null);
		LinearLayout layout = (LinearLayout) view
				.findViewById(R.id.id_recordlayout);
		for (int i = 0; i < fieldName.length; i++) {
			String name = fieldName[i];
			if ("_id".equals(name))
				continue;
			TextView tv = new TextView(getContext());
			tv.setText(fieldName[i]);
			EditText edit = new EditText(getContext());
			layout.addView(tv);
			layout.addView(edit);
		}

		AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
		dialog.setTitle(R.string.add_a_record);
		dialog.setView(view);

		dialog.setPositiveButton(R.string.ok,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {

					}
				});
		dialog.setNegativeButton(R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {

					}
				});
		dialog.show();

 

 

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:layout_height="fill_parent">
	<LinearLayout android:id="@+id/id_recordlayout"
		android:layout_width="fill_parent" android:layout_height="fill_parent"
		android:orientation="vertical" android:padding="10dip"></LinearLayout>
</ScrollView>

 

 

  • 大小: 15.8 KB
分享到:
评论
3 楼 rocbond 2012-02-07  
顶一个,,,解决了我的大问题。。。
2 楼 fonter 2010-12-06  
松鼠88 写道
请问在AlertDialog的每个条目中加个图片改怎么弄啊,楼主?

你可能参考http://fonter.iteye.com/blog/674971这个。。。
1 楼 松鼠88 2010-12-05  
请问在AlertDialog的每个条目中加个图片改怎么弄啊,楼主?

相关推荐

Global site tag (gtag.js) - Google Analytics