2012-04-24 139 views
4

這是我想要實現的: 我在桌上有很多表行。每行應該有兩個文本視圖,每個視圖的產品標題和副標題(副標題尚未實現)。應該左對齊。在右側,我想要一個微調器來選擇數量。RelativeLayout與MATCH_PARENT不起作用

文本來自數據庫,當然有不同的長度。

這裏是我想出迄今:

<ScrollView android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/barmenu" 
     android:background="#99ffff" 
     android:scrollbars="vertical"> 

     <TableRow 
     android:layout_height="wrap_content" 
     android:background="#ffff99" 
     android:layout_width="match_parent"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:background="#0000ff"> 

      <TextView 
       android:id="@+id/productTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="#88ffff" 
       android:ellipsize="end" 
       android:padding="2dp" 
       android:singleLine="true" 
       android:text="Product name" 
       android:textColor="#000000" 
       android:gravity="left" 
       android:textSize="13sp" 
       android:textStyle="bold" /> 

      <Spinner 
       android:gravity="right" 
       android:layout_height="40dp" 
       android:layout_toRightOf="@id/productTitle" 
       android:width="100dp" 
       android:layout_width="wrap_content" /> 
     </RelativeLayout> 
     </TableRow> 
     <TableRow 
     android:layout_height="wrap_content" 
     android:background="#ffff99" 
     android:layout_width="match_parent"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:background="#0000ff"> 

      <TextView 
       android:id="@+id/productTitle2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="#88ffff" 
       android:ellipsize="end" 
       android:padding="2dp" 
       android:singleLine="true" 
       android:text="Some long long long long name" 
       android:textColor="#000000" 
       android:gravity="left" 
       android:textSize="13sp" 
       android:textStyle="bold" /> 

      <Spinner 
       android:gravity="right" 
       android:layout_height="40dp" 
       android:layout_toRightOf="@id/productTitle2" 
       android:width="100dp" 
       android:layout_width="wrap_content" /> 
     </RelativeLayout> 
     </TableRow> 
    </TableLayout> 
</ScrollView> 

Screendump:

enter image description here

第一個問題是,RelativeLayout的不填寫表格的寬度行。第二個問題:紡紗人員不對齊。

我錯過了什麼?

問候 艾倫

回答

2

我會使其更簡單,重量更輕。對所有這4個視圖使用RelativeLayout。對齊右側的兩個旋鈕,並使textview的 - match_parent並添加toLeftOf相對微調器。我想你會看到你想要的。

+0

只是爲了說清楚...你的意思是每個TableRow有一個RelativeLayout,就像我的例子中那樣? – allanth 2012-04-24 10:26:45

+0

不,我的意思是隻有RelativeLayout,根本沒有Table *。 – 2012-04-25 00:08:40

4

機器人:fillViewport = 「真」

這一行添加到您的ScollView屬性,你就大功告成了:)

2

添加android:layout_weight="1"到你的RelativeLayout

相關問題