Saturday, 14 September 2013

Using layoutparams in relativeLayout with dp

Using layoutparams in relativeLayout with dp

I m making an app and i want to be able to move a view using its margins
dynamically. I tried using this :
RelativeLayout.LayoutParams params =
(RelativeLayout.LayoutParams)cover.getLayoutParams();
params.leftMargin= 470;
params.topMargin= 20;
cover.setLayoutParams(params); (cover is an ImageView)
The problem with this code its that it uses px instead of dp. I also tried
using DisplayMetrics to convert my px values to dp but failed . Can you
help me ?

No comments:

Post a Comment