Android view's getTop(), getLeft(), getX(), getY(), getWidth(), getHeight() methods

后端 未结 3 1777
我寻月下人不归
我寻月下人不归 2021-02-19 08:02

I am writing a drag and drop application and got really confused because of some parameters.

Please help to figure out.

First of all, I read the documentation fo

3条回答
  •  醉酒成梦
    2021-02-19 08:25

    You can get pixels from dp with

    float ht_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, ht, getResources().getDisplayMetrics());
    float wt_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, wt, getResources().getDisplayMetrics());
    

    As of the positioning question. getTop and getLeft are relative values and are based on your parent. Since the only parent of your ImageView is LinearLayout you are effectively positioning your ImageView directly below the ActionBar/ToolBar

    Also don't use an image for a circle, you can draw it easily with canvas.drawCircle it takes much less memory.

提交回复
热议问题