How to get size of user's screen in BaseAdapter?

Hello, there is a ImageAdapter and want to get the size of the user's screen to adjust GridView
imageView.setLayoutParams(new GridView.LayoutParams(320,320));

How to do it?
package com.ngapp.cngbelarus.ui.history;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageView;

import com.ngapp.cngbelarus.R;

public class ImageAdapter extends BaseAdapter {
 private Context Context;
 public Integer[] images = {
 R. drawable.avatar_1, R. drawable.avatar_2,
 R. drawable.avatar_3, R. drawable.avatar_4,
 R. drawable.avatar_5, R. drawable.avatar_6,
 R. drawable.avatar_7, R. drawable.avatar_8,
 R. drawable.avatar_9, R. drawable.avatar_10,
 R. drawable.avatar_11, R. drawable.avatar_12,
 R. drawable.avatar_13, R. drawable.avatar_14,
 R. drawable.avatar_15, R. drawable.avatar_16,
 R. drawable.avatar_17, R. drawable.avatar_18,
 R. drawable.avatar_19, R. drawable.avatar_20,
 R. drawable.avatar_21, R. drawable.avatar_22,
 R. drawable.avatar_23, R. drawable.avatar_24

 public ImageAdapter(Context c) {
 context = c;

 public int getCount() {
 return images.length;

 public Object getItem(int position) {
 return images[position];

 public long getItemId(int position) {
 return 0;

 public View getView(int position, View convertView, ViewGroup parent) {

 ImageView imageView = new ImageView(context);
 imageView.setLayoutParams(new GridView.LayoutParams(320,320));
 return imageView;
April 7th 20 at 10:42
1 answer
April 7th 20 at 10:44
Maybe this will help

Display d = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();

copied from here
at I tried, not working) - holden9 commented on April 7th 20 at 10:47
Hey, it works
old and new ways work, test on Android 9 - Ewell_Hoppe commented on April 7th 20 at 10:50
@Ewell_Hoppe, OK, recheck again. Thank you - holden9 commented on April 7th 20 at 10:53

Find more questions by tags Android