I got stuck in this, I don't know how to convert px to dp in MarginLayout
So this is my main MarginLayout set method
public static void setMargins (View v, int l, int t, int r, int b) {
if (v.getLayoutParams() instanceof LinearLayout.MarginLayoutParams) {
LinearLayout.MarginLayoutParams p = (LinearLayout.MarginLayoutParams) v.getLayoutParams();
p.setMargins(l, t, r, b);
v.requestLayout();
}
}
And this is on click listener where the element changes its marginLayout
ArrowUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!Switch){
setMargins(AdditionalOperations, 0, 0, 0, 800);
Switch = true;
}
else{
setMargins(AdditionalOperations, 0, 0, 0, 715);
Switch = false;
}
}
});
My goal is to conver pixels to Dp, and margin it in DP value, not px. I'm really stuck in this and can't get the idea