我使用GridView
in Fragmnet
,主机活动包括 SlidingMenu和我的网格项目使用简单的谷歌现在卡片样式。但即使我对适配器使用性能技巧(回收和持有人模式),我的 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;
}
}
网格视图项:
<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>
农场布局:
<?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>