【发布时间】:2015-07-24 00:09:01
【问题描述】:
我正在编写一个拖放应用程序,但由于某些参数而感到非常困惑。
请帮忙解答一下。
首先,我阅读了View类的文档,得到了以下解释。
getX() : The visual x position of this view, in pixels.
getY() : The visual y position of this view, in pixels.
getWidth() : Return the width of the your view.
getHeight() : Return the width of the your view.
getTop() : Top position of this view relative to its parent.
getLeft() : Left position of this view relative to its parent.
现在当我们完成官方文档后,让我们看看我们有什么。
我有一个原始大小为500x500 的图像,称为圆形。
这是我的应用程序的实际屏幕截图
这是布局的xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/circle" />
</LinearLayout>
现在我在担心什么。当我看我的本地人时,我得到以下内容,这真的让我感到困惑。
我认为getX() 和getY() 函数没有任何问题,因为它们实际上告诉我图像从哪里开始。
正如文档所述,getWidth() 和 getHeight 方法返回视图的宽度和高度,但监视窗口告诉我我的 getWidth() 和 getHeight 是 300,我真的无法理解,因为在我的 XML 中我已经将它们设置为 100dp,所以函数会以不同的测量值返回它们,以及如何将其转换为 dp。
最后,它告诉我 getTop() 和 getLeft 是 700 和 300,正如文档所述,它们是图像相对于其父图像的位置。但是我的父母不是线性布局,那么这些数字在屏幕定位方面意味着什么?
【问题讨论】:
标签: android view layoutparams