My Android advanced tour ------> how to add separators in multiple LinearLayout and android Separators
If you want to fit all Android versions, you can place a View on multiple LinearLayout to display the separation line. For example, put an ImageView component and set its background to the color or image of the separator line. The definition code of the separator line 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 later versions, LinearLayout supports direct display of separation lines. Set the android: showDividers attribute of the <LinearLayout> label to display the separation line at the corresponding position of LinearLayout. If multiple LinearLayout entries exist, the display effect is the same as that of LinearLayout.
Android: The showDividers attribute can be set to the following four values:
None: No separator line is displayed;
Beginning: display the separation line at the beginning of LinearLayout;
End: display the separation line at the end of Linearlayout;
Middle: display the separation line between every two components in LinearLayout:
In addition to setting the android: showDividers attribute, you also need to set the android: divider attribute, which indicates the image of the separator line and requires a Drawable ID
Android: divider = "@ drawable/shape" <! -- Split line Image --> android: showDividers = "middle | beginning | end | none" <! -- Split line position -->
1. android: divider = "@ drawable/shape"
Drawable can be an image file or a shape drawn in xml.
If the split line is an image, you can use the image directly. If you want to use the Color, you must use the shape to display it. It is useless to directly use the Color or Color.
When using shape, note that setting the size attribute does not display the split line without setting the width or height. If line is used, the fill color can only be displayed using stroke.
When using shape, you must add <size> for example:
[Java]View plaincopy
- <? Xml version = "1.0" encoding = "UTF-8"?>
- <Shape xmlns: android = "http://schemas.android.com/apk/res/android">
- <Solid android: color = "@ color/account_line"/>
- <Size android: height = "1px"/>
- </Shape>
2. android: showDividers = "middle | end | beginning | none"
Middle adds a split line in the middle of each item
End adds a split line in the last item of the whole.
Beginning adds a split line at the top of the whole
None
In Java code, you can use the following two methods to set android: showDividers and android: divider.
LinearLayout. setShowDividers: sets the android: showDividers attribute.
LinearLayout. setDividerDrawable: sets the android: divider attribute.
PS: see
Android custom controls elegantly implement split lines between elements (less than 3.0 supported)
Address: http://blog.csdn.net/lmj623565791/article/details/42407923
========================================================== ========================================================== ============================
Author: Ouyang Peng: Welcome to repost. sharing with others is the source of progress!
Reprinted Please retain the original address: http://blog.csdn.net/ouyang_peng
========================================================== ========================================================== ============================
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.