I am trying to use the method setLayoutParams in order to specify the graphical parameters of my table layout, but I am not sure whether the method setLayoutParams takes pixel values, or dip values, especially that in java the values stored seem to be pixel ones, for examples if I declare these two variables:
private int blockDimension = 50;
private int blockPadding = 2;
And then call the method :
tableRow.setLayoutParams(new LayoutParams( (blockDimension + 2 * blockPadding) * numberOfColumnsInMineField,blockDimension + 2 * blockPadding) );
Are they considered as being pixels or are they converted once passed to the method ? Then if they aren't, how can I set dip values in java ?
It takes pixels. To convert dp to pixels you can use this:
public int getPx(int dimensionDp) {
float density = getResources().getDisplayMetrics().density;
return (int) (dimensionDp * density + 0.5f);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With