2013-12-10 41 views
0

如何爲圖像創建android的佈局?如何爲圖像創建android的佈局?

layout image

我嘗試下面的代碼:

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="kkkkddd" 
      android:layout_marginLeft="100dp" 
      android:id="@+id/text_email" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/prompt_email" 
      android:id="@+id/text_label_email" 
      android:layout_toLeftOf="@id/text_email" /> 
     ... 

label_email被隱藏。

回答

1

你應該首先和設置把你的標籤的TextView它固定的寬度做到這一點。餘處價值的TextView到標籤的右側:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:text="@string/prompt_email" 
     android:id="@+id/text_label_email"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="kkkkddd" 
     android:toRightOf="@id/text_label_email" 
     android:id="@+id/text_email" /> 
0

嘗試線性佈局方向爲水平:)

+0

同樣的問題:如何將所有電視與圖像上的一條垂直線對齊? – HotIceCream

+0

將所有這些Linearlayouts放置在外部Linearlayout中,並且方向垂直。 –

+1

並在第一個電視中添加'android:gravity =「right」。好。但是嵌套佈局對性能不利。用RelativeLayout回答更好。 – HotIceCream

0

海事組織的LinearLayout會更適合用於這一目的。例如:

<LinearLayout 
    android:orienation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_weight="1" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:text="kkkkddd" 
     android:layout_marginLeft="100dp" 
     android:id="@+id/text_email" /> 

    <TextView 
     android:layout_weight="1" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:text="@string/prompt_email" 
     android:id="@+id/text_label_email" 
     android:layout_toLeftOf="@id/text_email" /> 

</LinearLayout> 

,你可以爲每一對

+0

如何將所有電視與圖像上的一條垂直線對齊? – HotIceCream

0

化妝父LinearLayout中。並使用內部linearLayouts。在innerlayouts重力水平。然後給它的兩個孩子,即「電子郵件」文本視圖&「[email protected]」體重應爲0.5。爲「電子郵件」設置右對齊,併爲「[email protected]」設置左對齊。

它會很好地工作。

如果有幫助,請選Voteup或標記爲真

+0

是的,它的工作原理。但更好地回答RelativeLayout。 – HotIceCream

+0

好投票。如果它對你有幫助 –