Skip to content

Instantly share code, notes, and snippets.

@w9jds
Last active February 1, 2024 10:23
Show Gist options
  • Save w9jds/22d8652bfaebfeb83407 to your computer and use it in GitHub Desktop.
Save w9jds/22d8652bfaebfeb83407 to your computer and use it in GitHub Desktop.
Expanding Info Panel on ImageCardView for Android TV
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
final ImageCardView cardView = new ImageCardView(mContext);
cardView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, final boolean isFocused) {
final View infoField = view.findViewById(R.id.info_field);
final TextView contentField = (TextView)view.findViewById(R.id.content_text);
final TextView titleField = (TextView)view.findViewById(R.id.title_text);
final Drawable mainImage = ((ImageView)view.findViewById(R.id.main_image)).getDrawable();
if (isFocused) {
((TextView)cardView.findViewById(R.id.title_text)).setMaxLines(3);
FrameLayout.LayoutParams infoLayout = new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
infoField.setLayoutParams(infoLayout);
RelativeLayout.LayoutParams contentLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
contentLayout.addRule(RelativeLayout.BELOW, R.id.title_text);
contentField.setLayoutParams(contentLayout);
}
else {
((TextView)cardView.findViewById(R.id.title_text)).setMaxLines(1);
}
}
});
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
cardView.setBackgroundColor(mContext.getResources().getColor(R.color.fastlane_background));
return new ViewHolder(cardView);
}
@oleynikd
Copy link

oleynikd commented Nov 3, 2014

Nice :) That was the first thing i thought when saw ImageCardView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment