Fixed height of tableRow Android

杀马特。学长 韩版系。学妹 提交于 2019-12-13 04:33:15

问题


I have a calendar that contains a tableLayout with 6 rows, each row contains 6 cells of type CelluleMensuelle (it extends a LinearLayout).

In the beginning, all rows have the same height, but when i add textviews to a cell, it increases the height of its row, how can i prevent this ? i want the rows to keep their initial height

here is my xml file 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>

回答1:


You need to set the android:weightSum attribute of the TableLayout, so if you have 6 rows and you want to keep the same height for them and each of the row has the attribute weight set to 1, the android:weightSum attribute of the TableLayout needs to be 6.



来源:https://stackoverflow.com/questions/17704376/fixed-height-of-tablerow-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!