我在GridView
中使用Fragmnet
,在SlidingMenu中使用主机操作,而我的网格项使用简单的Google即时卡样式。但我的gridView太迟了,即使我使用性能技巧我的适配器(回收和持有人模式)。
我的问题: 还有其他性能调整吗?或者我是否按照正确的方式进行表演? (GridView和适配器)
gridView适配器:
public class CustomGridAdapter extends ArrayAdapter<RbtItem> {
Context context;
int layoutResourceId;
ArrayList<RbtItem> data = new ArrayList<RbtItem>();
public CustomGridAdapter(Context context, int layoutResourceId,
ArrayList<RbtItem> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RecordHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
holder.imageItem = (ImageView) row.findViewById(R.id.item_image);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
RbtItem item = data.get(position);
holder.txtTitle.setText(item.getText());
holder.imageItem.setImageResource(R.drawable.bg);
return row;
}
static class RecordHolder {
TextView txtTitle;
ImageView imageItem;
}
}
gridView项:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/nowCardStyleRaw"
android:layout_width="100dp"
android:layout_height="140dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/item_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/bg" />
<TextView
android:id="@+id/item_text"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:ellipsize="none"
android:gravity="right"
android:maxLines="1"
android:textSize="18sp" />
<TextView
android:id="@+id/item_singer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="-20dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:ellipsize="none"
android:gravity="right"
android:maxLines="1"
android:textSize="11sp"
android:textColor="#FF4444" />
</TextView>
fargment布局:
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_rbt_list_grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e3e3e3"
android:columnWidth="97dp"
android:gravity="center"
android:numColumns="auto_fit"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="8dp"
android:stretchMode="columnWidth"
android:verticalSpacing="12dp" >
</GridView>