如何解决图库滚动会使整个视图无效
| 我的布局中有一个Gallery,以及一个ImageView和一些TextView小部件。不幸的是,我在慢速手机上的Gallery滚动性能较低。当我从包含ImageView和TextView的LinearLayout中删除背景图像时,问题消失了。 我为整个视图覆盖了onDraw(),并检查了rect片段-它始终是整个屏幕。好像每次我滚动图库(并且它无效)时,整个屏幕都无效。 当我仅滚动“画廊”小部件时,有什么方法可以避免全屏重绘? 谢谢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;
}
解决方法
您可能应该看一下有关Adapters和ConvertView的教程。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。