TableLayout table layout displays all views and tablelayout la s in the ViewGroup.
Design requirement: There are two views, ViewA and ViewB in the ViewGroup. Two views must be displayed in the ViewGroup within the screen range. If you do not allow the increase of ViewA, ViewB will be squeezed out of the screen, in this case, ViewB is allowed to stretch and not contract, and ViewA is allowed to contract.
The process is as follows:
When ViewA is reduced, ViewB follows the stretch ::
If the ViewA width is too long, for example, 9000dp or greater, because ViewB cannot be scaled down, the ViewB will remain unchanged after being restored to the configured width and will not be squeezed out of the screen. ViewA will automatically contract:
After the abstract logic, the above conditions must be met to achieve this design requirement. If LinerLayout, RelativeLayout, and FrameLayout are used, it is difficult to achieve the requirement because the scaling attribute setting is not stretched. This requirement is very similar to the implementation of Excel tables, so TableLayout can solve the problem perfectly, so the code is as follows:
<TableLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: stretchColumns = "1" // set the first column to be stretched to android: shrinkColumns = "0"> // you can set the drop-free column to allow <TableRow> <Button android: id = "@ + id/btn01" android: layout_width = "9000dp" android: layout_height = "200dp" android: background = "@ color/starfish_blue_normol" android: text = "Allowed To be shrunk \ nViewA"> </Button> <Button android: id = "@ + id/btn02" android: layout_width = "120dp" android: layout_height = "200dp" android: background = "@ color/red" android: text = "allowed to be stretched \ nViewB"> </Button> </TableRow> </TableLayout>