1

I need to change the cardView height according to screen height. how can I get the Screen Height inside the TileAdapter?

public static class ViewHolder extends RecyclerView.ViewHolder implements ItemTouchHelperViewHolder {

    public CardView cardView;

    // ........................

    public ViewHolder(final View itemView) {
        super(itemView);
        cardView = (CardView) itemView.findViewById(R.id.card_view);

        Display mdisp = itemView.getContext().getWindowManager().getDefaultDisplay();
        Point mdispSize = new Point();
        mdisp.getSize(mdispSize);
        height = mdispSize.y;

        Toast.makeText(itemView.getContext(),height,Toast.LENGTH_SHORT).show();
        cardView.setMinimumHeight(height);
    }

    // ..........................
}
fredmaggiowski
  • 2,232
  • 3
  • 25
  • 44
Anne
  • 31
  • 5

1 Answers1

0

Try this - Get screen dimensions in pixels

Use DisplayMetrics instead of Display

Community
  • 1
  • 1
Onkar Nene
  • 1,359
  • 1
  • 17
  • 23