Android 如何在同一个RelativeLayout中左右对齐项目

Android 如何在同一个RelativeLayout中左右对齐项目,android,android-layout,xamarin.android,Android,Android Layout,Xamarin.android,下面是我为ListView的自定义行编写的XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="80dp" android:background="#EFEFF

下面是我为ListView的自定义行编写的XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:background="#EFEFF4"
    android:paddingLeft="10dp">
    <ImageView
        android:layout_height="20dp"
        android:layout_width="20dip"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:background="@drawable/CircleRed"
        android:id="@+id/statusColor" />

    <TextView
        android:id="@+id/tvStatusName"
        android:layout_toRightOf="@id/statusColor"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textColor="#696969"
        android:paddingRight="20dp"
        android:layout_marginLeft="10dp"
        android:gravity="center_vertical|left"
        android:layout_centerVertical="true"
        android:text="Customer Satisfaction"
        android:textSize="18dip" />

    <ImageView
        android:layout_alignParentRight="true"
        android:layout_height="20dp"
        android:layout_width="10dp"
        android:layout_toRightOf="@id/tvStatusName"
        android:layout_centerVertical="true"
        android:src="@drawable/Right"/>
</RelativeLayout


只需从箭头图像视图中删除
android:layout\u-toRightOf=“@id/tvStatusName”
,并将
android:layout\u-toLefttOf=“@id/imageViewRight.”


将imageViewRight id指定给右箭头图像视图。

只需从箭头图像视图中删除
android:layout\u-toRightOf=“@id/tvStatusName”
,并设置
android:layout\u-toleftof=“@id/imageViewRight”。

Use linear layout instead of relative layout.Your code some what like this:`<?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-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/view_margin_medium">

        <TextView
            android:id="@+id/lbl_driver_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="@color/color_black"
            android:text="Hari Piorko" />

        <TextView
            android:id="@+id/lbl_vehicle_no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/lbl_driver_name"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal"
            android:text="MH-08-6789" />

        <RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_toRightOf="@+id/lbl_vehicle_no"
            android:layout_weight="0">

            <RadioButton
                android:id="@+id/radio_driver"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:layout_gravity="right"
                android:buttonTint="@color/color_green" />

        </RadioGroup>

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@color/color_gray" />

</LinearLayout>`
将imageViewRight id指定给右箭头图像视图。

使用线性布局而不是相对布局。您的代码如下所示:`
Use linear layout instead of relative layout.Your code some what like this:`<?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-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/view_margin_medium">

        <TextView
            android:id="@+id/lbl_driver_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="@color/color_black"
            android:text="Hari Piorko" />

        <TextView
            android:id="@+id/lbl_vehicle_no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/lbl_driver_name"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal"
            android:text="MH-08-6789" />

        <RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_toRightOf="@+id/lbl_vehicle_no"
            android:layout_weight="0">

            <RadioButton
                android:id="@+id/radio_driver"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:layout_gravity="right"
                android:buttonTint="@color/color_green" />

        </RadioGroup>

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@color/color_gray" />

</LinearLayout>`
`
使用线性布局而不是相对布局。您的代码如下所示:`
`

您是否尝试在设备或仿真器中安装相似的东西?右箭头是否在emulator中可见,请检查一次。 如果没有显示,请尝试下面的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:background="#EFEFF4"
    android:paddingLeft="10dp">
    <ImageView
        android:layout_height="20dp"
        android:layout_width="20dip"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:background="@mipmap/ic_launcher"
        android:id="@+id/statusColor" />

    <TextView
        android:id="@+id/tvStatusName"
        android:layout_toRightOf="@id/statusColor"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textColor="#696969"
        android:paddingRight="20dp"
        android:layout_marginLeft="10dp"
        android:gravity="center_vertical|left"
        android:layout_centerVertical="true"
        android:text="Customer Satisfaction"
        android:textSize="18dip" />

    <ImageView
        android:layout_alignParentRight="true"
        android:layout_height="20dp"
        android:layout_width="30dp"
        android:layout_centerVertical="true"
        android:padding="5dp"
        android:src="@mipmap/ic_launcher" />
</RelativeLayout>

不需要更改代码。
希望它对您有所帮助。

您是否尝试在设备或模拟器中安装类似的东西?右箭头是否在emulator中可见,请检查一次。 如果没有显示,请尝试下面的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:background="#EFEFF4"
    android:paddingLeft="10dp">
    <ImageView
        android:layout_height="20dp"
        android:layout_width="20dip"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:background="@mipmap/ic_launcher"
        android:id="@+id/statusColor" />

    <TextView
        android:id="@+id/tvStatusName"
        android:layout_toRightOf="@id/statusColor"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textColor="#696969"
        android:paddingRight="20dp"
        android:layout_marginLeft="10dp"
        android:gravity="center_vertical|left"
        android:layout_centerVertical="true"
        android:text="Customer Satisfaction"
        android:textSize="18dip" />

    <ImageView
        android:layout_alignParentRight="true"
        android:layout_height="20dp"
        android:layout_width="30dp"
        android:layout_centerVertical="true"
        android:padding="5dp"
        android:src="@mipmap/ic_launcher" />
</RelativeLayout>

不需要更改代码。
希望对您有所帮助。

在带有android:src=“@drawable/Right”的imageview中删除android:layout\u toRightOf=“@id/tvStatusName”,在带有android:src=“@drawable/Right”的imageview中删除android:layout\u toRightOf=“@id/tvStatusName”