转载请标明出处:
http://blog.youkuaiyun.com/zq2114522/article/details/51112281;
本文出自:【梁大盛的博客】
getLeft,getTop,getRight,getBottm傻傻分不清.
通过下面图片已经很清晰的把该说的说明白了!
注意:
1.getLeft,getTop,getRight,getBottm,getWidth是View左上角的锚点相对父布局的像素.
2.可以看到父布局在布局文件里面设置了android:padding="20dp".因为density=1.5实质转换为像素应该是30px.
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.dsliang.viewdemo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GREEN"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<com.example.dsliang.viewdemo.ViewDemo
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GRAY" />
</LinearLayout>
</LinearLayout>