图库滚动使整个视图无效

时间:2011-05-30 09:32:23

标签: android android-layout android-ui

我的布局中有一个Gallery,还有一个ImageView和一些TextView小部件。不幸的是,我在慢速手机上的画廊滚动性能很低。当我从包含ImageView和TextView的LinearLayout中删除背景图像时,问题消失了。 我为整个视图覆盖onDraw()并检查剪辑rect - 它始终是整个屏幕。看起来每当我滚动图库(并且它无效)时,整个屏幕都会失效。 当我只滚动Gallery小部件时,有没有办法避免全屏重绘?

谢谢

private class GalleryAdapter extends ArrayAdapter<WeatherDisplayInfo> {

    LayoutInflater mInflater;
    Context mContext;

    public GalleryAdapter(Context context) {
        super(context, R.layout.gallery_item_view, mForecastData);

        mContext = context;
        mInflater = LayoutInflater.from(context);

    }

    public int getCount() {
        return mForecastData.size();
    }

    public WeatherDisplayInfo getItem(int position) {
        return mForecastData.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    private class ViewHolder {

        public TextView text_date;
        public TextView text_forecast;
        public TextView text_temperature;

        public TextView text_pressure;
        public TextView text_humidity;
        public TextView text_windspeed;

        public ImageView weather_image;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;


        if(convertView == null) {

            if(position == getCount() - 1) {

                convertView = mInflater.inflate(R.layout.logo_view, null);

                holder = new ViewHolder();

                // store view holder
                convertView.setTag(holder);

            } else {

                convertView = mInflater.inflate(R.layout.gallery_item_view, null);

                holder = new ViewHolder();

                holder.text_date = (TextView) convertView.findViewById(R.id.text_date);
                holder.text_forecast = (TextView) convertView.findViewById(R.id.text_desc);
                holder.text_temperature = (TextView) convertView.findViewById(R.id.text_temp);

                holder.text_pressure = (TextView) convertView.findViewById(R.id.text_pressure);
                holder.text_humidity = (TextView) convertView.findViewById(R.id.text_humidity);
                holder.text_windspeed = (TextView) convertView.findViewById(R.id.text_wind);

                holder.weather_image = (ImageView) convertView.findViewById(R.id.image_weather_view);;

                // store view holder
                convertView.setTag(holder);             

                convertView.setDrawingCacheEnabled(true);
                convertView.buildDrawingCache();

            }                               

        } else {

            holder = (ViewHolder) convertView.getTag();

        }

        // set view data

        return convertView;
    }

1 个答案:

答案 0 :(得分:0)

您应该查看Adapters和ConvertView的教程。