Add split line to LinearLayout after 3.0

Source: Internet
Author: User

android:divider= "@drawable/shape" <!--分割线图片--> android:showDividers= "middle|beginning|end"  <!--分割线位置-->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 colorExample:
<LinearLayoutAndroid:id= "@+id/buttons_container"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:divider= "@drawable/spacer_medium"android:orientation= "Horizontal"android:showdividers= "Middle">              <ButtonAndroid:id= "@+id/btn_first"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Button_1" />                          <ButtonAndroid:id= "@+id/btn_second"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Button_2" />                          <ButtonAndroid:id= "@+id/btn_third"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Button_3" />              </LinearLayout>

Spacer_medium is defined as follows:

<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Rectangle">      <sizeAndroid:width= "@dimen/spacing_medium"Android:height= "@dimen/spacing_medium" />      <SolidAndroid:color= "@color/divider_color" />  </Shape>

if we want to simply set a gap for linearlayout, we don't need to fill the color. such as this:
<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Rectangle">     <sizeAndroid:width= "@dimen/spacing_medium"Android:height= "@dimen/spacing_medium" />     <SolidAndroid:color= "@android: Color/transparent" /> </Shape>

And there's no bug when you dynamically change elements.

The bug here is:

We set the gap in the traditional way, there is no problem when the three buttons are displayed, but there is a problem when the dynamic changes to two buttons.

1. When three buttons are

2. When two buttons are

with the above method, the layout spacing will be the same each time. Reference from:http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0105/2268.htmlhttp://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0105/2266.html

Add split line to LinearLayout after 3.0

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.