Advertisement
Guest User

getView()

a guest
Nov 24th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. public View getView(int position, View convertView, ViewGroup parent) {
  2.         ImageView iv;
  3.         final Document document = getItem(position);
  4.         final int currentColumnCount = Utils.getInteger(R.integer.grid_column_count);
  5.  
  6.         if (convertView == null) {
  7.             iv = new ImageView(App.getContext());
  8.             iv.setAdjustViewBounds(true);
  9.         } else {
  10.             iv = (ImageView)convertView;
  11.         }
  12.  
  13.         float margin = Utils.dp2px(Utils.getDimension(R.dimen.common_padding_small))*(currentColumnCount-1);
  14.         int ivWidth = (int) ((Utils.getDisplayXY()[0]-margin) / currentColumnCount);
  15.         float thumbRatio = (float) document.getHeight() / (float)document.getWidth();
  16.  
  17.         int ivHeight = (int)( ivWidth * thumbRatio);
  18.  
  19.         if (ivHeight >= parent.getHeight() ){ //TODO remove after GridView lib new release
  20.             ivHeight = parent.getHeight() - (int)Utils.getDimension(R.dimen.common_padding_large);
  21.         }
  22.  
  23.         iv.setLayoutParams(new ViewGroup.LayoutParams(ivWidth,ivHeight));
  24.         ImageLoader.getInstance().displayImage(document.getPath_thumbnail(), iv);
  25.  
  26.         return iv;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement