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