public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolderList holder;
if (convertView == null) {
holder = new ViewHolderList();
convertView = LayoutInflater.from(context)
.inflate(R.layout.children_row_list, null);
position=position+2;
Log.d("list position::", ""+position);
holder.img_children_view=(ImageView)convertView.findViewById(R.id.image_children);
holder.text_child_name=(TextView)convertView.findViewById(R.id.text_children_name);
holder.text_child_month=(TextView)convertView.findViewById(R.id.text_children_month);
holder.text_group_name=(TextView)convertView.findViewById(R.id.text_children_group);
holder.img_children_view1=(ImageView)convertView.findViewById(R.id.image_children1);
holder.text_child_name1=(TextView)convertView.findViewById(R.id.text_children_name1);
holder.text_child_month1=(TextView)convertView.findViewById(R.id.text_children_month1);
holder.text_group_name1=(TextView)convertView.findViewById(R.id.text_children_group1);
Resources r = getResources();
float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 90, r.getDisplayMetrics());
int pixel_height = (int) pixels;
holder.img_children_view.setLayoutParams(new LinearLayout.LayoutParams(80 , 80));
holder.img_children_view1.setLayoutParams(new LinearLayout.LayoutParams(80 , 80));
convertView.setTag(holder);
}
else{
holder = (ViewHolderList) convertView.getTag();
}
if(position %2 == 0){
// System.out.println(position + " is even number.");
holder.text_child_name.setText(children_list.get(position).getFirst_name());
holder.text_child_name.setText(children_list.get(position).getFirst_name());
holder.text_child_month.setText(display_month);
holder.text_group_name.setText(children_list.get(position).getGroup_name());
Bitmap bitmap = decodeFile(new File( Environment.getExternalStorageDirectory()+"/com.x/y/"+children_list.get(position).getPhoto()), ConfigurationData.staffImageSize,ConfigurationData.staffImageSize);
//holder.img_children_view.setImageBitmap(bitmap);
}
else{
// System.out.println(position+ " is odd number.");
holder.text_child_name1.setText(children_list.get(position).getFirst_name());
holder.text_child_name1.setText(children_list.get(position).getFirst_name());
holder.text_child_month1.setText(display_month);
holder.text_group_name1.setText(children_list.get(position).getGroup_name());
Bitmap bitmap1 = decodeFile(new File( Environment.getExternalStorageDirectory()+"/com.x/y/"+children_list.get(position).getPhoto()), ConfigurationData.staffImageSize,ConfigurationData.staffImageSize);
//holder.img_children_view1.setImageBitmap(bitmap1);
}
return convertView;
} //closing getview
}
答案 0 :(得分:2)
我建议使用android GridView
,参数numColumns
等于2
答案 1 :(得分:0)
使用列数android:numColumns="2"
创建Gridview。
在xml中:
<GridView
android:id="@+id/sdcard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:numColumns="2">
</GridView>
在java代码中:
public View getView(int position, View convertView,
ViewGroup parent) {
final ViewHolderList holder;
if (convertView == null) {
holder = new ViewHolderList();
convertView = LayoutInflater.from(context)
.inflate(R.layout.children_row_list, null);
position=position+2;
Log.d("list position::", ""+position);
holder.img_children_view=(ImageView)convertView.findViewById(R.id.image_children);
holder.text_child_name=(TextView)convertView.findViewById(R.id.text_children_name);
holder.text_child_month=(TextView)convertView.findViewById(R.id.text_children_month);
holder.text_group_name=(TextView)convertView.findViewById(R.id.text_children_group);
holder.img_children_view1=(ImageView)convertView.findViewById(R.id.image_children1);
holder.text_child_name1=(TextView)convertView.findViewById(R.id.text_children_name1);
holder.text_child_month1=(TextView)convertView.findViewById(R.id.text_children_month1);
holder.text_group_name1=(TextView)convertView.findViewById(R.id.text_children_group1);
Resources r = getResources();
float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 90, r.getDisplayMetrics());
int pixel_height = (int) pixels;
holder.img_children_view.setLayoutParams(new LinearLayout.LayoutParams(80 , 80));
holder.img_children_view1.setLayoutParams(new LinearLayout.LayoutParams(80 , 80));
convertView.setTag(holder);
}
else{
holder = (ViewHolderList) convertView.getTag();
}
// System.out.println(position + " is even number.");
holder.text_child_name.setText(children_list.get(position).getFirst_name());
holder.text_child_name.setText(children_list.get(position).getFirst_name());
holder.text_child_month.setText(display_month);
holder.text_group_name.setText(children_list.get(position).getGroup_name());
Bitmap bitmap = decodeFile(new File( Environment.getExternalStorageDirectory()+"/com.x/y/"+children_list.get(position).getPhoto()), ConfigurationData.staffImageSize,ConfigurationData.staffImageSize);
//holder.img_children_view.setImageBitmap(bitmap);
return convertView;
} //closing getview
}