Simple Application of the border of tablelayouyt in Android

Source: Internet
Author: User

Tablelayouyt layout is difficult to control the border,

First take a look at the following picture

There is no boder attribute in tablelayout, which is quite tangled. I don't know what Google thinks, but I don't need to talk about the border mechanism.

Tablelayout border layout: in fact, the background color is set to the background color. The overlapping part is the border we want.

<Tablerow
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: Background = "@ color/gray"> <! -- Here we set the background color of tablerow, and the view is loaded in tablerow -->

<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: Background = "@ color/White" <! -- When setting the background color for loading the view, it is important to add the Android: layout_margin attribute to make the view and row have a distance, so that the border will come out. -->
Android: gravity = "center"
Android: layout_margin = "1dp"
Android: text = "date"/>

This is a method, but you will seriously find that the split line in the middle is thicker than the top and bottom lines on both sides, because Android is added to each textview: layout_margin = "1dp", margin is 1 for both the left and right sides, and overlap between the left and right sides of the second table, if you want to adjust the value, you can set the upper, lower, and lower sides of margin in detail,

In fact, it is not obvious that you set the line details.

Another method is to customize the background of the table view. By using the shape. xml file, we only need to reference it in the view. This method is simple. We recommend that you use this method later.

<Shape xmlns: Android = "http://schemas.android.com/apk/res/android">

<! -- Fill color -->
<Gradient
Android: angle = "0"
Android: endcolor = "# ffffff"
Android: startcolor = "# ffffff"/>
<! -- Radians of the four corners -->
<Stroke
Android: width = "0.5dp"
Android: color = "# dbdbdb"/>
<! -- Angle -->
<Corners Android: radius = "3dp"/>

<Padding
Android: Bottom = "5dp"
Android: Left = "5dp"
Android: Right = "5dp"
Android: Top = "5dp"/>

</Shape>

The above is a simple application of the border. To make a good display, You need to carefully deploy it, but it is OK to know how to implement it.

Related Article

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.