List of usage examples for android.widget GridView getRequestedColumnWidth
public int getRequestedColumnWidth()
From source file:com.appdevper.mediaplayer.adater.MediaItemViewHolder.java
static View setupGridView(Activity activity, View convertView, ViewGroup parent, ContentItem item, int state) { if (sColorStateNotPlaying == null || sColorStatePlaying == null) { initializeColorStateLists(activity); }/*w w w . jav a 2 s.c om*/ MediaItemViewHolder holder; Integer cachedState = STATE_INVALID; if (convertView == null) { convertView = LayoutInflater.from(activity).inflate(R.layout.media_grid_item, parent, false); holder = new MediaItemViewHolder(); holder.layGrid = (RelativeLayout) convertView.findViewById(R.id.layGrid); holder.mImageBack = (ImageView) convertView.findViewById(R.id.imgBack); holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq); holder.mTitleView = (TextView) convertView.findViewById(R.id.title); holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description); convertView.setTag(holder); } else { holder = (MediaItemViewHolder) convertView.getTag(); cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache); } GridView grid = (GridView) parent; int size = grid.getRequestedColumnWidth(); holder.mTitleView.setText(item.toString()); holder.mDescriptionView.setText(item.getSubtitle()); int w = holder.layGrid.getLayoutParams().width; // holder.layGrid.setLayoutParams(new GridView.LayoutParams(w, w)); holder.mImageBack.setLayoutParams(new RelativeLayout.LayoutParams(w, w)); if (item.isContainer()) { holder.mImageBack.setImageResource(item.getDefaultResource()); } else { Utils.downloadBitmap(activity.getResources(), item, holder.mImageBack); } // If the state of convertView is different, we need to adapt the view to the // new state. if (cachedState == null || cachedState != state) { switch (state) { case STATE_PLAYABLE: holder.mImageView.setImageDrawable(activity.getDrawable(R.drawable.ic_play_arrow_black_36dp)); holder.mImageView.setImageTintList(sColorStateNotPlaying); holder.mImageView.setVisibility(View.VISIBLE); break; case STATE_PLAYING: AnimationDrawable animation = (AnimationDrawable) activity .getDrawable(R.drawable.ic_equalizer_white_36dp); holder.mImageView.setImageDrawable(animation); holder.mImageView.setImageTintList(sColorStatePlaying); holder.mImageView.setVisibility(View.VISIBLE); if (animation != null) animation.start(); break; case STATE_PAUSED: holder.mImageView.setImageDrawable(activity.getDrawable(R.drawable.ic_equalizer1_white_36dp)); holder.mImageView.setImageTintList(sColorStateNotPlaying); holder.mImageView.setVisibility(View.VISIBLE); break; default: holder.mImageView.setVisibility(View.GONE); } convertView.setTag(R.id.tag_mediaitem_state_cache, state); } return convertView; }