My Android advanced tour ------ & gt; how to add separators in multiple LinearLayout and android Separators

Source: Internet
Author: User

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
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <Shape xmlns: android = "http://schemas.android.com/apk/res/android">
  3. <Solid android: color = "@ color/account_line"/>
  4. <Size android: height = "1px"/>
  5. </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.

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.