My Android Step-by-step tour------> How to add a divider line to multiple LinearLayout

Source: Internet
Author: User


If you want to fit all Android versions, you can place a view that displays a divider line in multiple linearlayout. For example, to put a ImageView component and then set its background to the color or image of the divider line, the definition code for the divider view is as follows:

<imageview           android:layout_width= "fill_parent"          android:layout_height= "1DP"          android:background= "# FFFFFF "          />  
The effect is as follows:


in Android3.0 and above, LinearLayout supports direct display of divider lines. The Android:showdividers property of the Settings <LinearLayout> label can then display the divider in the corresponding position linearlayout. If you have more than one linearlayout, the display effect is the same as dividing the line between linearlayout.

The Android:showdividers property can set the following 4 values:
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, you also set the Android:divider property, which represents the image of the divider, requiring a drawable ID

android:divider= "@drawable/shape" <!--split Line picture--  android:showdividers= "Middle|beginning|end|none" <!- -Split Line Location--  

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

Drawable can be a picture file, or it can be the shape of an XML drawing.

Split line If it is a picture then use the image directly, if you want to use the color you must use shape to display, direct use of colors or color is useless
When using shape, be aware that setting the Size property does not set the width height divider to be displayed, and if you use line that fill color can only use the stroke to display the color

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

[Java]View Plaincopy
  1. <?xml version= "1.0" encoding= "Utf-8" ?>
  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 Add a split line between each item

End adds a split line to the last item in the whole

Beginning add split line at the top of the whole

None None


The following two methods can be 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.



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

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

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

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

  


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

My Android Step-by-step tour------> 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.