Android 如何将(图像视图和文本视图)向左对齐,将(图像视图和文本视图)向右对齐

Android 如何将(图像视图和文本视图)向左对齐,将(图像视图和文本视图)向右对齐,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我有一个标题栏,它有两个ImageView 一个左对齐,一个右对齐,如下图所示 <RelativeLayout android:id="@+id/headersection" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop

我有一个标题栏,它有两个ImageView

一个左对齐,一个右对齐,如下图所示

<RelativeLayout
    android:id="@+id/headersection"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="#181b1c" >



    <ImageView
        android:id="@+id/img_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_margin="5dp"
        android:layout_marginRight="10dp"
        android:contentDescription="@string/img_des"
        android:src="@drawable/play" />



    <ImageView
        android:id="@+id/img_backicon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerHorizontal="true"
        android:layout_margin="5dp"
        android:layout_marginLeft="10dp"
        android:contentDescription="@string/img_des"
        android:src="@drawable/back" />
</RelativeLayout>

我想在每个图像旁边放一个TextView,这样左ImageView旁边会有一个TextView(与左ImageView的左右对齐),右ImageView旁边会有一个TextView(与右ImageView的右对齐)

我已经尝试了大约30种不同的编码方式,但都搞不懂

下面是我正在尝试做的一个例子

    <RelativeLayout
        android:id="@+id/headersection"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="#181b1c" >

<!-- NEED TO PUT A TEXTVIEW HERE THAT ALIGNS TO THE RIGHT IMAGE BELOW -->

    <TextView
        android:id="@+id/RIGHT_TEXT"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="RIGHT TEXT HERE"
        android:textColor="@color/Category_Title_Color"
        android:textSize="20sp" />

        <ImageView
            android:id="@+id/img_play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_margin="5dp"
            android:layout_marginRight="10dp"
            android:contentDescription="@string/img_des"
            android:src="@drawable/play" />


<!-- NEED TO PUT A TEXTVIEW HERE THAT ALIGNS TO THE LEFT IMAGE BELOW -->

    <TextView
        android:id="@+id/LEFT_TEXT"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="LEFT TEXT HERE"
        android:textColor="@color/Category_Title_Color"
        android:textSize="20sp" />

        <ImageView
            android:id="@+id/img_backicon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerHorizontal="true"
            android:layout_margin="5dp"
            android:layout_marginLeft="10dp"
            android:contentDescription="@string/img_des"
            android:src="@drawable/back" />
    </RelativeLayout>

当我尝试这样做时,文本总是与图像重叠或没有正确对齐

任何帮助都将不胜感激

****更新**** 板球007的答案似乎对我很有用。。。如果有人需要查看,下面是完成的代码

<RelativeLayout
    android:id="@+id/headersection"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@color/colorbuttonbar" >


    <TextView
        android:id="@+id/img_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:layout_margin="5dp"
        android:layout_marginRight="10dp"
        android:text="MUSIC - "
        android:textStyle="bold"
        android:textColor="@color/Notification_Bar_Title_Color"
        android:drawableRight="@drawable/play" />


    <TextView
        android:id="@+id/img_backicon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerHorizontal="true"
        android:gravity="center_vertical"
        android:layout_margin="5dp"
        android:layout_marginLeft="10dp"
        android:text=" - GO BACK"
        android:textStyle="bold"
        android:textColor="@color/Notification_Bar_Title_Color"
        android:drawableLeft="@drawable/back" />






</RelativeLayout>

您可能根本不需要
图像视图

TextView
具有左右图像的两个属性:


比如说,

<TextView
        android:id="@+id/img_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_marginRight="10dp"
        android:text="MUSIC - "
        android:drawableRight="@drawable/play" /> <!-- See here -->

您可能根本不需要
图像视图

TextView
具有左右图像的两个属性:


比如说,

<TextView
        android:id="@+id/img_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_marginRight="10dp"
        android:text="MUSIC - "
        android:drawableRight="@drawable/play" /> <!-- See here -->

您是否尝试过使用
android:layout\u-tolightof
android:layout\u-toLeftOf
以及
android:layout\u-toEndOf

<RelativeLayout 
    android:id="@+id/headersection"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="#181b1c">

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/textView" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/textView2" />

    <ImageView
        android:id="@+id/img_backicon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/back"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/textView"
        android:layout_toEndOf="@+id/textView" />

    <ImageView
        android:id="@+id/img_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/play"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/textView2"
        android:layout_toStartOf="@+id/textView2" />

</RelativeLayout>

您是否尝试过使用
android:layout\u-tolightof
android:layout\u-toLeftOf
以及
android:layout\u-toEndOf

<RelativeLayout 
    android:id="@+id/headersection"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="#181b1c">

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/textView" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/textView2" />

    <ImageView
        android:id="@+id/img_backicon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/back"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/textView"
        android:layout_toEndOf="@+id/textView" />

    <ImageView
        android:id="@+id/img_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/play"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/textView2"
        android:layout_toStartOf="@+id/textView2" />

</RelativeLayout>


天哪。。。。。你是认真的吗LOL,所以我会将textview向左和向右对齐,然后根据textview使用属性android:drawableLeft和android:drawableRight将图像附加到每个textview?继续尝试:)这对我有效,我将在更新的文档中包含完成的代码question@skapaid你可以把它作为答案贴在下面。你的问题不应该包含你的解决方案。。。。。你是认真的吗LOL,所以我会将textview向左和向右对齐,然后根据textview使用属性android:drawableLeft和android:drawableRight将图像附加到每个textview?继续尝试:)这对我有效,我将在更新的文档中包含完成的代码question@skapaid你可以把它作为答案贴在下面。你的问题不应该包含你的答案