TableLayout table layout displays all views and tablelayout la s in the ViewGroup.

Source: Internet
Author: User

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>
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.