My Android Advanced tour------> How to add a divider line to multiple LinearLayout

Source: Internet
Author: User


If you want to fit all Android version numbers, you can place a view that displays a divider line in multiple linearlayout.

For example, put a imageview component. Then set its background to the color or image of the divider line, and the definition code for the divider view is as follows:

<imageview           android:layout_width= "fill_parent"          android:layout_height= "1DP"          android:background= "# FFFFFF "          />  
Effects such as the following:

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "style=" font-size:24px ">


at Android3.0 and above, LinearLayout supports the direct display of the divider line. The Android:showdividers property of the Settings <LinearLayout> label can then display the divider line in the corresponding position of the linearlayout. Suppose there are multiple linearlayout, and the display effect is the same as dividing the line between linearlayout.

The Android:showdividers property is capable of setting 4 values such as the following:
None: No dividing line is displayed;
Beginning: Displays the dividing line at the beginning of the LinearLayout;
End: Displays the divider line at the end of the linearlayout;
Middle: Displays the divider between each of the two components in the LinearLayout:
In addition to setting the Android:showdividers property, set the Android:divider property. This property represents the image of the divider, which requires a drawable ID

android:divider= "@drawable/shape" <!--cutting line picture-  android:showdividers= "Middle|beginning|end|none" <!- -Cutting line position--  

1, android:divider= "@drawable/shape"

Drawable can be a picture file, or it can be an XML-drawn shape.

The cut line is assumed to be a picture, so you can use the image directly, assuming that you want to use a shape to display the color, it's not practical to use colors or color directly.
When using shape, be aware that setting the Size property does not set the width and height of the cut line will not be displayed, assuming that the fill color using lines can only use the stroke to display the color

When using shape, be sure to join <size> for example:

[Java]View Plaincopy
  1. <?

    Xml version=" 1.0 "  encoding= " utf-8 " ?>&NBSP;&NBSP;

  2. <shape xmlns:android=" http://schemas.android.com/apk/res/android " >&NBSP;&NBSP;
  3.      <solid android:color=" @color/account_line " &NBSP;/>&NBSP;&NBSP;
  4.     <size android:height=" 1px " &NBSP;/>&NBSP;&NBSP;
  5. </shape>

2, android:showdividers = "Middle|end|beginning|none"

Middle the cutting line in the middle of each item

End adds a cut line to the last item in the total

Beginning add cutting line at the top of the overall

None None


The following two methods are used in Java code to set android:showdividers and Android:divider

Linearlayout.setshowdividers: Sets the Android:showdividers property.

Linearlayout.setdividerdrawable: Sets the Android:divider property.


PS: able to participate

Android self-defined controls elegantly implement the cutting lines between elements (support 3.0 below)

Address: http://blog.csdn.net/lmj623565791/article/details/42407923




====================================================================================

Ouyangpeng welcome reprint, sharing with people is the source of progress!

Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng

====================================================================================


My Android Advanced tour------&gt; How to add a divider line to multiple LinearLayout

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.