读书人

Android AlertDialog动态添加组件和pa

发布时间: 2012-08-24 10:00:21 作者: rapoo

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

先上图

?

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>

?

?

1 楼 松鼠88 2010-12-05 请问在AlertDialog的每个条目中加个图片改怎么弄啊,楼主? 2 楼 fonter 2010-12-06 松鼠88 写道请问在AlertDialog的每个条目中加个图片改怎么弄啊,楼主?
你可能参考http://fonter.iteye.com/blog/674971这个。。。 3 楼 rocbond 2012-02-07 顶一个,,,解决了我的大问题。。。

读书人网 >Android

热点推荐