2012-02-01 37 views
0

這是佈局我有:產生看起來像這樣的列表項安卓:如何強制左對齊項目來包裝,而不是右對齊項目?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:minHeight="?android:attr/listPreferredItemHeight"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"> 
     <TextView 
      android:id="@+id/customer_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:paddingLeft="4dip"/> 
     <TextView 
      android:id="@+id/ticket_number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14sp" 
      android:paddingLeft="6dip"/> 
    </LinearLayout> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:gravity="right"> 
     <TextView 
      android:id="@+id/total" 
      android:gravity="right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:paddingRight="6dip"/> 
     <TextView 
      android:id="@+id/date" 
      android:gravity="right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14sp" 
      android:paddingRight="6dip"/> 
    </LinearLayout> 
</LinearLayout> 

enter image description here

,正如你所看到的,這是一個有點難看。我想對包裝頂部的藍色框,如果右上方盒爲紅色,並有底部行完全獨立的理由往上頂的,這樣的日子不換行可言,無論什麼樣的頂行的樣子。什麼是完成這一任務的最好方法是什麼?

回答

1

使用TableLayout,使其具有shrinkColumns="0"和specifify客戶名稱/票務#是在第0列,您還可以設置爲strechColums要擴展,以適應的,所以大概列1至擴大日期列。

另一種選擇是不是把它們放在垂直線性佈局,而是爲每個行的水平的。

+0

感謝。我已經張貼在一個單獨的回答這個問題的實現,但接受了你的是正確的。 – moonlightcheese 2012-02-01 21:46:16

0

實現:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:shrinkColumns="0" 
     android:stretchColumns="1" 
     android:minHeight="?android:attr/listPreferredItemHeight"> 
    <TableRow> 
     <TextView 
      android:id="@+id/customer_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_span="2" 
      android:textSize="18sp" 
      android:paddingLeft="4dip"/> 
     <TextView 
      android:id="@+id/total" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="1" 
      android:gravity="right" 
      android:layout_gravity="right" 
      android:textSize="18sp" 
      android:paddingRight="6dip"/> 
    </TableRow> 
    <TableRow> 
     <TextView 
      android:id="@+id/ticket_number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:textSize="14sp" 
      android:paddingLeft="6dip"/> 
     <TextView 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="1" 
      android:layout_span="2" 
      android:layout_gravity="right" 
      android:gravity="right" 
      android:textSize="14sp" 
      android:paddingRight="6dip"/> 
    </TableRow> 
</TableLayout> 

enter image description here