How to change the height of my layout programmatically?

1

I have a little doubt .. I am setting up an item_layout for the cells of a list .. There is a way to handle the height of the cells, according to the data that they load ... I'm using

PercentRelativeLayout oidit;
 oidit = (PercentRelativeLayout) itemView.findViewById(R.id.idit);
oidit.getLayoutParams().height = 100;

to enlarge some cells of the list programmatically, the problem is: on a 1080 dpi screen it works fine but on a larger screen like 1440 dpi or a tablet

oidit.getLayoutParams().height = 100;

is not enough to show the data remains I have to add more dp: not 100dp but 200 or 250 dp at height. I wanted to know if there is a way for the given value to adapt to any screen?

    
asked by user62207 22.10.2018 в 17:39
source

2 answers

2

Create a LayoutParams and configure it to your layout using setLayoutParams ():

PercentRelativeLayout oidit;
oidit = (PercentRelativeLayout) itemView.findViewById(R.id.idit);

LayoutParams params = oidit.getLayoutParams();
params.height = 100;
params.width = 100;
oidit.setLayoutParams(params);
    
answered by 22.10.2018 в 19:26
1

I managed to solve it in another way .. See the resolution of the patanlla in question I hope you serve another .. there's my code (I'm using BaseAdapter ...)

   DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display displ = wm.getDefaultDisplay();
String displayName = displ.getName();
Point size = new Point();
displ.getSize(size);
int width = size.x;
int height = size.y;
int heightPixels = displayMetrics.heightPixels;
int widthPixels = displayMetrics.widthPixels;
int densityDpi = displayMetrics.densityDpi;
float xdpi = displayMetrics.xdpi;
float ydpi = displayMetrics.ydpi;
int screenHeight = displ.getHeight();
int screenWidth = displ.getWidth();

if (widthPixels>=1440){
                oidit.getLayoutParams().height = 210;
            }else if(widthPixels<=1440){
                oidit.getLayoutParams().height = 100;
            }

This code is a bit dirty because it brings everything you need to know about your screen as information Hopefully, it serves Somebody

    
answered by 22.10.2018 в 22:11