I have been working on an android tv app.I have list of movies which i populated inside the BrowserFragment
class.I have a presenter class that make use of ImageCardView
to show the movie thumbnail.I am trying to customize the imagecardview on Selected.I wanted it to look like the pic here.On selection of particular ImageCardView
the thumbnail will increase in size but the base alignment should be the same as the other unselected ones as shown in the pic.
EDIT Pic Link https://www.dropbox.com/s/habpjnrlwh1se8v/sample.png?dl=0
EDIT Presenter class
public class CardPresenter extends Presenter {
private int mSelectedBackgroundColor = -1;
private int mDefaultBackgroundColor = -1;
private Drawable mDefaultCardImage;
class ViewHolder extends Presenter.ViewHolder {
HashMap<Integer,Object> ObjectsList=new HashMap<>();
public ViewHolder(View view) {
super(view);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
mDefaultBackgroundColor = R.color.default_background;
mSelectedBackgroundColor = R.color.selected_background;
mDefaultCardImage = parent.getResources().getDrawable(R.drawable.lb_card_shadow_focused, null);
ImageCardView cardView = new ImageCardView(parent.getContext()) {
@Override
public void setSelected(boolean selected) {
updateCardBackgroundColor(this, selected);
super.setSelected(selected);
}
};
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
updateCardBackgroundColor(cardView, false);
return new ViewHolder(cardView);
}
private void updateCardBackgroundColor(ImageCardView view, boolean selected) {
int color = selected ? mSelectedBackgroundColor : mDefaultBackgroundColor;
// Both background colors should be set because the view's
// background is temporarily visible during animations.
view.setBackgroundColor(color);
view.findViewById(R.id.info_field).setBackgroundColor(color);
}
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
Movie movie = (Movie) item;
ImageCardView cardView = (ImageCardView) viewHolder.view;
cardView.setTitleText(movie.getName());
cardView.setContentText(movie.getCategory());
if (movie.getImgResUrl() != 0) {
// Set card size from dimension resources.
Resources res = cardView.getResources();
// int width = res.getDimensionPixelSize(R.dimen.card_width);
// int height = res.getDimensionPixelSize(R.dimen.card_height);
cardView.setMainImageDimensions(300, 300);
Glide.with(cardView.getContext())
.load(movie.getImgResUrl())
.error(mDefaultCardImage)
.into(cardView.getMainImageView());
}
}
@Override
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
ImageCardView cardView = (ImageCardView) viewHolder.view;
// Remove references to images so that the garbage collector can free up memory.
cardView.setBadgeImage(null);
cardView.setMainImage(null);
}
}
Any help will be greatly appreciated.Thanks