Alignment of items in row when using TableLayout
Im trying to figure out how to line up items in each row of a table (TableLayout) - ideally I want the center of each cell to line up horizontally. The documentation isn't very clear on what's possible with TableLayout. Each cell has a different view widget so I thought a tabular layout would work well but they are all different sizes and default to top-left alignment inside each cell.
If I can't line them up then Ill 开发者_如何学Goneed to use a different layout manager
Set the layoutGravity of the view in the cell to be center-vertical, center-horizontal, center.
The layoutGravity tell the views parent how it wants to be displayed, so this will cause the table row to center it in the cell.
You can use this code to center a view within a table layout
layout.setGravity(Gravity.CENTER);
精彩评论