2011-05-30 52 views
1

我的佈局中有一個畫廊,還有一個ImageView和一些TextView小部件。不幸的是,我在慢速手機上獲得低滾動性能。當我從包含ImageView和TextView的LinearLayout中移除背景圖像時,問題消失。 我對整個視圖進行了ondraw()操作,並檢查了剪輯矩形 - 它始終是整個屏幕。它看起來像我每次滾動畫廊(並且無效)整個屏幕無效。 當我只滾動圖庫小部件時,有什麼辦法可以避免全屏重繪嗎?畫廊滾動使整個視圖無效

感謝

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; 
    } 
+0

發佈您在代碼庫適配器中使用的代碼。您可能不會重新正確地使用具有類似問題的正確視圖 – pankajagarwal 2011-05-30 09:45:28

+0

,但由於某些原因庫存在滾動視圖(或textview可滾動)時無法釋放內存,因此該表面會出現外存錯誤。 Gallery組件中存在一個已知的bug,它根本不允許適配器視圖重用(convertView始終爲空) – dparnas 2012-01-17 18:42:28

回答

0

你或許應該看看在適配器和ConvertView的教程。