android gridview慢滚动

时间:2013-01-19 06:23:45

标签: android gridview

我有一个带有gridview的android活动,每个单元格包含一个带有单个字符的textview(因此屏幕上一次有大约60-70个字符/单元格)。网格视图的滚动速度慢得令人无法接受。我尝试用listview替换gridview,listview的滚动速度要快得多。我怎样才能加快速度呢?

活动布局为:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnWidth="56dp"
        android:numColumns="auto_fit" >
    </GridView>

</LinearLayout>

每个单元格内部都是这种布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textSize="40sp" />

</LinearLayout>

活动的代码是:

public class TestGridActivity  extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grid_activity);
        GridView gridView = (GridView) findViewById(R.id.gridView1);
        ArrayList<Map<String, String>> list = getData();
        SimpleAdapter arrayAdapter = new SimpleAdapter(this, list, 
            R.layout.grid_layout, new String[] { "literal"}, 
            new int[] { R.id.textView1});
        gridView.setAdapter(arrayAdapter);
    }

}

编辑:pks要求发布适配器代码,上面的代码我使用了一个通用的simpleAdapter,但是我尝试了一个自定义视图,但没有帮助。

public class GridAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<Map<String, String>> list;
    private LayoutInflater inflater;
    public static class ViewHolder {
    TextView textView1;
    int position;
    }
    public GridAdapter(Context c, ArrayList<Map<String, String>> l) {
        context = c;
        list = l;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.grid_layout, null);
            holder = new ViewHolder();
            holder.textView1 = (TextView) convertView.findViewById(R.id.textView1);
            holder.position = position;
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView1.setText(list.get(position).get("character"));
        return convertView;
    }
}

我也尝试过提前创建所有视图,但这并没有帮助滚动速度。

0 个答案:

没有答案