在xamarin.android中的absoluteLayout中定位到右下角

时间:2017-12-15 22:27:19

标签: xaml android-layout xamarin.android

我有一个像这样的绝对布局

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
       //stuff
    </LinearLayout>
    <Button
        android:text="test"
        android:textStyle="bold"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_x="10dp"
        android:layout_y="10dp"
         />
</AbsoluteLayout>

它需要一个按钮并将其定位在距离屏幕顶部10dp和屏幕左侧10dp的左上角位置。

我需要在那里添加另一个按钮并将其放置在屏幕的右下角,但我不知道如何设置从底部和右侧位置计算的位置(layout_x和y),它们目前是从顶部和左侧。

这可能吗?如果可以解决问题,我甚至愿意使用相对或类似的布局,而不是绝对布局。

1 个答案:

答案 0 :(得分:1)

自API3以来,

AbsoluteLayout已被弃用。

您可以使用RelativeLayout代替,并为按钮设置android:layout_alignParentBottom="true"android:layout_alignParentRight="true"

    <Button
    android:text="Button"
    android:textStyle="bold"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" />