我正在尝试在GridView中显示日历,该日历已创建视图代码(不是XML)。 但我只能显示1行GridView而不是所有行。
我相信我错过了一些属性或设置了错误的属性:
protected void onCreate(Bundle savedInstanceState) {
Panel panel = new Panel(context);
ScrollView mainScrollView = (ScrollView)findViewById(R.id.scrollView1);
mainScrollView.addView(panel);
class Panel extends LinearLayout {
public Panel(Context context) {
super();
super.setMinimumHeight(400); //LayoutParams.MATCH_PARENT);
GridView view = new GridView(context);
view.setMinimumHeight(400); //(LayoutParams.MATCH_PARENT);
view.setMinimumWidth(LayoutParams.MATCH_PARENT);
view.setColumnWidth(60);
view.setNumColumns(7);
view.setVerticalSpacing(10);
view.setHorizontalSpacing(10);
view.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
view.setGravity(Gravity.CENTER);
view.setAdapter(new MYAdapter(context));
}
public class MyAdapter extends BaseAdapter {
public MyAdapter(Context context) {
super();
//insert 30 elements into a list
}
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = new TextView(mContext);
String str = list.get(position);
textView.setText(str.toCharArray(), 0, str.toCharArray().length);
if (convertView == null) {
textView.setLayoutParams(new GridView.LayoutParams(65, 65));
textView.setPadding(2, 2, 2, 2);
} else {
textView = (TextView) convertView;
}
return textView;
}
}
如果我将高度设置为MATCH_PARENT或特定数字,则没有区别。