2017-02-03 53 views
0

我有具有兩個ImageViews如何對齊(一個的ImageView和一個TextView)的左側和(一個ImageView的和一個TextView)至

一個是左對齊並且一個是對準的標題欄的權利向右,像下面

<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> 

當我試圖做一個例子,文字不停重疊圖像或不正確對齊。

任何幫助,將不勝感激

**** ****更新從 的cricket_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> 

回答

4

您可能完全不需要ImageView

TextView有左,右圖像的兩個屬性:

android:drawableLeft

android:drawableRight


例如,

<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 --> 
+0

哇靠.....你是認真的LOL 所以我會對準TextView的向左和向右,只是使用附加的圖像,每個的TextView屬性android:drawableLeft和android:drawableRight取決於textview? – skapaid

+0

繼續嘗試吧:) –

+0

這對我有用,我將在更新後的問題中包含完成代碼 – skapaid

0

您是否嘗試過使用android:layout_toRightOfandroid:layout_toLeftOf以及android:layout_toStartOfandroid:layout_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> 
相關問題