2013-07-17 38 views
0

我有一个包含6行tableLayout的日历,每行包含6个CelluleMensuelle类型的单元格(它扩展了LinearLayout)。固定桌面高度Android

在开始时,所有行都具有相同的高度,但是当我向单元格添加textviews时,它会增加行的高度,我该如何防止这种情况?我要对行保持其初始高度

这里是我的xml文件 calendrier_calendriermensuel.xml

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="3"       
     android:text="Lundi" 
     android:background="@drawable/ligne_bordure" 
    /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="3"       
     android:text="Mardi" 
     android:background="@drawable/ligne_bordure" 
    /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="3"       
     android:text="Mercredi" 
     android:background="@drawable/ligne_bordure" 
    /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="3"       
     android:text="Jeudi" 
     android:background="@drawable/ligne_bordure" 
    /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="3"       
     android:text="Vendredi" 
     android:background="@drawable/ligne_bordure" 
    /> 
</LinearLayout> 

<TableLayout 
    android:id="@+id/layout_calendriermensuel" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:background="#FFFFFF"> 

    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     /> 
     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     /> 
     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     /> 
     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     /> 
     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     />         
    </TableRow> 
    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     /> 
     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     /> 
     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     /> 
     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     /> 
     <com.thinline.dm21.utils.CelluleMensuelle 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@drawable/ligne_bordure" 
     />         
    </TableRow> 

    <!-- 4 others tablerows --!> 
</TableLayout> 

</LinearLayout> 
+0

请参阅http://radioal.blogspot.in /2011/05/stretching-rows-in-android-tablelayout.html – jeevamuthu

回答

0

您需要设置了android:中TableLayout的weightSum属性,所以如果你有6行并且您希望为它们保持相同的高度,并且每行都将属性权重设置为1,TableLayout的android:weightSum属性需要为6.

+0

我做了什么哟你说,它不工作 – Blacksword888

+0

嗯它应该是...尝试设置每个TableRow的背景颜色,以确保行本身没有相同的高度 – user2579825

+0

之前添加textviews,他们都有相同的高度 – Blacksword888