J'ai créé une table simple avec une longueur de texte variable. J'utilise layout_height=wrap_content
dans ma rangée de table. Si vous voyez l'image, il y a un grand espace entre l'élément suivant et le précédent. Si je règle la hauteur, les espaces resteront visibles en paysage. Je ne sais pas où le réparer. J'ai surtout utilisé des styles ... donc c'est bizarre que certains fonctionnent et d'autres pas.Le contenu ne s'enroule pas lorsque layout_height = wrap_content dans la ligne
sampleLayout.xml
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:background="@color/form_background"
android:shrinkColumns="*"
android:stretchColumns="*">
<!--Table header-->
<TableRow
style="@style/table_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/th_component"
style="@style/table_header"
android:layout_height="match_parent"
android:layout_weight="2.8"
android:text="@string/tableH_komponen"/>
<TextView
android:id="@+id/th_marks"
style="@style/table_header"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/tableH_markah"/>
<TextView
android:id="@+id/th_demerits"
style="@style/table_header"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:text="@string/tableH_demerit"/>
<TextView
android:id="@+id/th_notes"
style="@style/table_header"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="@string/tableH_catatan"/>
</TableRow>
<!--Component C1-->
<TableRow
style="@style/table_row"
android:layout_height="wrap_content">
<TextView
style="@style/table_attr"
android:text="@string/c1"/>
<TextView
android:id="@+id/tv_cC1"
style="@style/table_component"
android:text="@string/cC1"
/>
<TextView
android:id="@+id/tv_mc1"
style="@style/table_marks"
android:layout_height="wrap_content"
android:text="@string/_6"/>
<CheckBox
android:id="@+id/checkBox_c1"
style="@style/table_demerit"
android:layout_height="wrap_content"/>
<ImageButton
android:id="@+id/btn_c1"
style="@style/table_notes"
android:layout_height="wrap_content"
android:text="@string/catatan"/>
</TableRow>
<!--Component C2-->
<TableRow
style="@style/table_row"
android:layout_height="wrap_content">
<TextView
style="@style/table_attr"
android:text="@string/c2"/>
<TextView
android:id="@+id/tv_cC2"
style="@style/table_headComponent"
android:text="@string/cC2"/>
<ImageButton
android:id="@+id/btn_c2"
style="@style/table_notes"
android:layout_height="wrap_content"
android:text="@string/catatan"/>
</TableRow>
<TableRow
style="@style/table_row"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_cC2_1"
style="@style/table_subComponent"
android:text="@string/cC2_1"/>
<TextView
android:id="@+id/tv_mC2_1"
style="@style/table_marks"
android:layout_height="match_parent"
android:text="@string/_1"/>
<CheckBox
android:id="@+id/checkBox_c2_1"
style="@style/table_subDemerit"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
style="@style/table_row"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_cC2_2"
style="@style/table_subComponent"
android:layout_height="wrap_content"
android:text="@string/cC2_2"/>
<TextView
android:id="@+id/tv_mC2_2"
style="@style/table_marks"
android:layout_height="wrap_content"
android:text="@string/_1"/>
<CheckBox
android:id="@+id/checkBox_c2_2"
style="@style/table_subDemerit"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</FrameLayout>
strings.xml
<resources>
<!--Case C-->
<string name="cC1">Pemeriksaan kesihatan ke atas semua pengendali makanan:
\n - Mendapat suntikan pelalian anti-tifoid
\n - Menghadiri Latihan Pengendali Makanan </string>
<string name="cC2">Tahap kebersihan diri yang baik:</string>
<string name="cC2_1">- Berpakaian bersih dan bersesuaian</string>
<string name="cC2_2">- Memakai apron yang bersih dan berpenutup kepala</string>
</resources>
styles.xml
<resources>
<!--kpkt table header-->
<style name="table_header">
<item name="android:textSize">@dimen/textSize_subheading</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/table_textcolor</item>
<item name="android:background">@color/table_background</item>
<item name="android:padding">@dimen/text_padding</item>
<item name="android:layout_width">0dp</item>
<item name="android:gravity">center</item>
</style>
<!--table style-->
<style name="table_row">
<item name="android:gravity">end</item>
<item name="android:layout_width">0dp</item>
<item name="android:weightSum">5</item>
</style>
<style name="table_attr">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.3</item>
<item name="android:gravity">center</item>
</style>
<style name="table_component">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">2.5</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
</style>
<style name="table_marks">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:padding">8dp</item>
</style>
<style name="table_demerit">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.7</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:visibility">visible</item>
</style>
<style name="table_notes">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">0.5</item>
<item name="srcCompat">@drawable/ic_edit</item>
<item name="android:contentDescription">catatan</item>
<!--<item name="android:drawableBottom">@drawable/ic_edit</item>-->
<!--<item name="android:drawableTop">@drawable/ic_edit</item>-->
</style>
<!--kpkt table head component-->
<style name="table_headComponent">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">40dp</item>
<item name="android:padding">@dimen/text_padding</item>
<item name="android:layout_weight">4.2</item>
</style>
<!--kpkt table subcomponent-->
<style name="table_subDemerit">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1.2</item>
<item name="android:visibility">visible</item>
</style>
<style name="table_subComponent">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">40dp</item>
<item name="android:padding">8dp</item>
<item name="android:layout_weight">2.5</item>
</style>
</resources>