When applying styles, many of their parameters are for some reason ignored.

<LinearLayout android:id="@+id/regionColumn" android:layout_width="170dp" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/regionHeader" style="@style/AppTheme.TableHeaderTextView" android:layout_width="80dp" android:text="@string/region" /> </LinearLayout> 

For example, when adding a TextView with a style to such a container, all indents and height are ignored. The style itself:

 <style name="AppTheme.TableTextView"> <item name="android:textSize">8pt</item> <item name="android:paddingTop">10dp</item> <item name="android:paddingBottom">10dp</item> <item name="android:paddingLeft">10dp</item> <item name="android:paddingRight">10dp</item> <item name="android:layout_height">80dp</item> </style> 

Why is this happening and how to solve this problem?

PS TableHeaderTextView is a column header. TableTextView is a regular table cell.

  • Apparently sealed off - TableHeaderTextView and TableTextView - Android Android
  • Not. TableHeaderTextView is a column header. TableTextView is a regular table cell. - Streletz

1 answer 1

Understood himself.

It is necessary to specify indents in LayoutParams , otherwise they are ignored.

 TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); params.setMargins(5, 20, 20, 30); textView.setLayoutParams(params); 
  • Dimensions, indents and everything in LayoutParams are not “stylish” attributes and cannot be applied to all widgets at once. Therefore, they need to be set individually: in the markup (in the <TextView> in this example) or programmatically, as you did. - woesss