2012-09-16 29 views
1

好的,我正在嘗試做的是:將imageview設置在右側,3個文本視圖將位於相對於圖像左側的左側。使用以下XML代碼,imageview位於左側,3個textview位於imageview的右側。將我的意見對齊

下面是它的外觀現在: enter image description here

正如我所說的,我希望圖像右側對齊,並在圖像左側的3個textviews。

因此,這裏是當前xml:http://pastebin.com/r68S1QKv

如果我改變的LinearLayout到RelativeLayout的(這樣我就可以使用alignParentRight =真),textviews堆疊在彼此,而不是垂直顯示。

建議,請問?

編輯:貌似我還沒弄清楚想要的樣子,這裏有我想要的一個例證:enter image description here

+0

您對XML有什麼期待?包含TextView的LinearLayout應該是父容器中的第一個元素,然後是ImageView - 這樣TextView將位於ImageView的左側。 – Egor

+0

我沒有想到除此之外,我問我怎麼能讓這些意見在活動的右側>>> – idish

+0

@Egor忘記標記 – idish

回答

1

使用此Code.Use RelativeLayout的父&分配的android:layout_alignParentRight = 「true」 以他的孩子這個設定所有觀點在右側。

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <LinearLayout 
     android:layout_width="wrap_content" 
    android:layout_marginRight="20dp" 

     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:orientation="horizontal" > 


     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/row_title" 
       style="bold" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="hey1" /> 

      <TextView 
       android:id="@+id/row_subtitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="hey2" /> 

      <TextView 
       android:id="@+id/row_postcode_city" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="hey3" /> 
     </LinearLayout> 


     <ImageView 
      android:id="@+id/icon" 
      android:layout_marginRight="20dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

</RelativeLayout> 
+0

非常感謝你的回答,請看看我編輯的問題 – idish

+0

使用這個我希望現在對你很好 – yokees

+0

優秀的EXCELENT !!!非常感謝! – idish

1

你能做什麼 - 是讓外RelativeLayout,讓你像alignParentRight=true,將文本以獨立線性佈局(垂直方向)查看視圖,將LinearLayout與文本視圖對齊到圖像視圖(layout_toLeftOf="@+id/img_id")的左邊緣。

這是我能做到以下這種方法:

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_toLeftOf="@+id/img" 
     android:orientation="vertical" 
     android:id="@+id/text_container"> 

     <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="text1"/> 
     <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="text2"/> 
     <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="text3"/> 

    </LinearLayout> 

    <ImageView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/icon" 
     android:id="@+id/img"/> 

</RelativeLayout> 
+0

感謝您的幫助,我試過你的代碼但這不是我所要求的。我會試着再次解釋自己,也許你知道我能做些什麼。 – idish

+0

現在我明白了...請嘗試我的更新回答 –

+0

下面是我想要做的事情的一個例子:http://imageshack.us/a/img341/1336/31032887.png – idish