getLeft,getTop,getRight,getBottm区别
Posted dsliang12
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了getLeft,getTop,getRight,getBottm区别相关的知识,希望对你有一定的参考价值。
转载请标明出处:
http://blog.csdn.net/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>
以上是关于getLeft,getTop,getRight,getBottm区别的主要内容,如果未能解决你的问题,请参考以下文章
android view之getLeft(),getRight(),getTop(),getBottom(),getX(),getY(),getRawX(),getRawY(),getTranslat