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
- <?xml version= "1.0" encoding= "Utf-8" ?>
- <shape xmlns:android=" http://schemas.android.com/apk/res/android " >&NBSP;&NBSP;
- <solid android:color=" @color/account_line " &NBSP;/>&NBSP;&NBSP;
- <size android:height=" 1px " &NBSP;/>&NBSP;&NBSP;
- </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