启用 centerInParent 的 Button 的位置。 Xamarin.android
Position of Button with centerInParent enabled. Xamarin.android
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/absoluteLayout1">
<Button
p1:layout_width="101.5dp"
p1:id="@+id/Start"
p1:text="@string/StartBtn"
p1:layout_height="101.5dp"
p1:layout_centerInParent="true" />
<WebView
p1:layout_centerInParent="true"
p1:layout_height="match_parent"
p1:layout_width="match_parent"
p1:id="@+id/Sky" />
</RelativeLayout>
所以我有这个例子,我想获得按钮的 x/y 坐标。我该怎么做?或者容器的高度,这样我就可以计算出来了。 Resources.DisplayMetrics.HeightPixels 没有用,因为它 returns 屏幕大小。
您可以使用 GetLocationInWindow or GetLocationOnScreen 获取按钮位置。您需要传递一个包含两个元素的数组,该数组将在这些方法 return.
时填充
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/absoluteLayout1">
<Button
p1:layout_width="101.5dp"
p1:id="@+id/Start"
p1:text="@string/StartBtn"
p1:layout_height="101.5dp"
p1:layout_centerInParent="true" />
<WebView
p1:layout_centerInParent="true"
p1:layout_height="match_parent"
p1:layout_width="match_parent"
p1:id="@+id/Sky" />
</RelativeLayout>
所以我有这个例子,我想获得按钮的 x/y 坐标。我该怎么做?或者容器的高度,这样我就可以计算出来了。 Resources.DisplayMetrics.HeightPixels 没有用,因为它 returns 屏幕大小。
您可以使用 GetLocationInWindow or GetLocationOnScreen 获取按钮位置。您需要传递一个包含两个元素的数组,该数组将在这些方法 return.
时填充