Android RelativeLayout在另一个元素边框上对齐元素

Dar*_*ski 2 android android-layout android-xml

我试图使文本视图与RelativeLayout中另一个imageview的左边框对齐,但我遇到了麻烦,我无法实现这一点.任何人都可以告诉我如何实现这一目标?

在此输入图像描述

在此输入图像描述

这是我当前的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="wrap_content"
    android:layout_marginBottom="15dp"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/main_item_bg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY" />

    <RelativeLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/blackalha"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:weightSum="100" >

        <TextView
            android:id="@+id/main_item_cont"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/main_item_nmb"
            android:paddingLeft="5dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/white" />

        <ImageView
            android:id="@+id/main_item_ic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@color/app_purple"
            android:src="@drawable/bacal" />

        <TextView
            android:id="@+id/main_item_nmb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/main_item_ic"
            android:background="@drawable/saric"
            android:gravity="center"
            android:textColor="#333333" />

    </RelativeLayout>

    <TextView
        android:id="@+id/main_item_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/main_item_bg"
        android:layout_margin="5dp"
        android:maxWidth="200dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@android:color/white" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Pal*_*lak 6

Try this
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<ImageView
    android:id="@+id/main_item_bg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:contentDescription="@string/app_name"
    android:scaleType="fitXY" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="80dip"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/main_item_cont"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:paddingLeft="5dp"
            android:text="dsgffdufsdfdfsdfdsfsdfsdfdsfdf"
            android:inputType="textMultiLine"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/white" />


        <ImageView
            android:id="@+id/main_item_ic"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dip"
            android:layout_alignParentRight="true"
            android:layout_toRightOf="@+id/main_item_cont"
            android:background="@android:color/black"
            android:src="@drawable/ic_launcher" />


        <TextView
            android:id="@+id/main_item_nmb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:layout_alignTop="@+id/main_item_cont"
            android:layout_toRightOf="@+id/main_item_cont"
            android:background="@android:color/white"
            android:text="10"
            android:textColor="@android:color/white" />
    </RelativeLayout>


<TextView
    android:id="@+id/main_item_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@+id/main_item_bg"
    android:layout_margin="5dp"
    android:maxWidth="200dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/white" />
Run Code Online (Sandbox Code Playgroud)