C# Android Xamarin-在RelativeLayout中将控件右侧与右边距对齐

C# Android Xamarin-在RelativeLayout中将控件右侧与右边距对齐,c#,android,xml,android-layout,xamarin,C#,Android,Xml,Android Layout,Xamarin,我正在使用RelativeLayout来显示我的UI 我想在左上角有一个标题,在右上角有一个图片。 两个项目的上方和侧面(左侧或右侧)都需要有一个小间距 对于我的标题来说,这非常有效,但我似乎无法将我的图像向右对齐,也无法设置右边距 这是axml代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialogContainer" and

我正在使用RelativeLayout来显示我的UI

我想在左上角有一个标题,在右上角有一个图片。 两个项目的上方和侧面(左侧或右侧)都需要有一个小间距

对于我的标题来说,这非常有效,但我似乎无法将我的图像向右对齐,也无法设置右边距

这是axml代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dialogContainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFF"
    android:paddingBottom="25dip">

<TextView
    android:id="@+id/dialogTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:layout_marginTop="10dip"
    android:textColor="#158849"
    android:textSize="25dip" />

<ImageView
    android:id="@+id/dialogLoading"
    android:layout_width="26dip"
    android:layout_height="26dip"
    android:background="@drawable/LoadingAnimation"
    android:layout_marginTop="10dip"
    android:layout_alignParentRight="true" 
    android:layout_marginRight="25dip" /> <!--this doesn't work, there is no spacing-->

<TextView
    android:id="@+id/dialogMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000"
    android:textSize="18dip"
    android:layout_marginTop="15dp"
    android:layout_marginLeft="12dip"
    android:layout_marginRight="15dip"
    android:layout_below="@+id/dialogTitle" />
</RelativeLayout>

其他可能有帮助的事情: 这个项目应该可以在安卓2.3上构建

我不是直接将此布局分配给活动


相反,它用作自定义对话框的视图。

使用相对布局的
布局\u toLeftOf
属性:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dialogContainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFF"
    android:paddingBottom="25dip">
    <TextView
        android:id="@+id/dialogTitle"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:layout_marginTop="10dip"
        android:textColor="#158849"
        android:textSize="25dip"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/dialogTitle"
        android:layout_width="wrap_content" />
    <ImageView
        android:id="@+id/dialogTitle"
        android:layout_width="26dip"
        android:layout_height="26dip"
        android:background="@drawable/LoadingAnimation"
        android:layout_alignParentRight="true"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:layout_alignParentTop="true" />
<!--this doesn't work, there is no spacing-->
</RelativeLayout>


更新了我的答案

所以你是说:我需要把我的图片“放在”我的标题的左边?然后创建一个边距将我的图像推到右边?我的标题是可变的,所以我的大小也会改变…它应该在图像的左侧,无论内容长度如何(我认为-没有在相对布局中发挥太多作用)-你可以很容易地测试这一点。。这是一个相对布局,其中每个布局都是相对于其他(其他)布局定位的。您不需要为其他布局(imageview)创建边距-只需将align parent top and right设置为true即可-因为父级是相对布局本身…但我希望我的imageview靠在右侧,并留一点边距。它不应该依赖于左控件(标题)所做的任何事情是的,它应该与
android:layout\u alignParentRight=“true”
(父控件是相对布局本身)