第一种,多条目,在优化 BaseAdapter 里面写
在它 public View getView(int position, View view, ViewGroup parent) {};上面写//多条目 @Override public int getViewTypeCount() { return 2; } @Override public int getItemViewType(int position) { return position % 2; } 第二种 多条目 一,item布局<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="match_parent"> <ImageView android:id="@+id/iv" android:layout_width="150dp" android:layout_height="100dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" /> </LinearLayout> </LinearLayout> 二,item1布局<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" /> </LinearLayout> 三,在优化中写多条目class MyAdapter extends BaseAdapter { @Override public int getCount() { return list1.size(); } @Override public Object getItem(int position) { return list1.get(position); } @Override public long getItemId(int position) { return position; } //控制有几种子布局 @Override public int getViewTypeCount() { return 2; } @Override public int getItemViewType(int position) { if (position%2 == 0){ return 0; }else { return 1; } } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; ViewHolder1 holder1 = null; int type = getItemViewType(position); if (type == 0){ if (convertView == null) { holder = new ViewHolder(); convertView = View.inflate(MainActivity.this, R.layout.item, null); holder.imageView = convertView.findViewById(R.id.iv); holder.textView01 = convertView.findViewById(R.id.tv_title); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.textView01.setText(list1.get(position).getTitle()); ImageLoader.getInstance().displayImage(list1.get(position).getPicUrl(),holder.imageView); }else { if (convertView == null){ holder1 = new ViewHolder1(); convertView = View.inflate(MainActivity.this,R.layout.item1,null); holder1.textView01 = convertView.findViewById(R.id.tv_title); convertView.setTag(holder1); }else { holder1 = (ViewHolder1) convertView.getTag(); } holder1.textView01.setText(list1.get(position).getTitle()); } return convertView; } } class ViewHolder { ImageView imageView; TextView textView01; } class ViewHolder1 { TextView textView01; }