How to Create a split line for a View, such
We can see three split lines that can be used to create a view that looks good, for example, adding a split line between buttons.
This example adds a split line between the three buttons in LinearLayout.
These three examples may be easy to implement, and I believe there will be better implementation methods.
1 manually add the LinearLayout split line
We can create a View, which is a split line, as long as you simply add this split line between buttons.
The implementation of the split line is as follows:
<View android:layout_height="fill_parent" android:layout_width="1dp" android:background="#90909090" android:layout_marginBottom="5dp" android:layout_marginTop="5dp"/>
So the whole layout, as pictured, becomes:
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:orientation="horizontal"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" >
2. Define divider in LinearLayout
You can set a view divider for LinearLayout, which is obviously a good solution, especially the number of child buttons in LinearLayout.
This must be used in API level 11 or later.
Let's first define the split line style:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <size android:width="1dp" /> <solid android:color="#90909090" /></shape>
Set the style of the split line to LinearLayout:
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:divider="@drawable/separator" android:showDividers="middle" android:orientation="horizontal"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" >android:divider="@drawable/separator"android:showDividers="middle"
3. Set the ButtonBarStyle for the container component (the default is the split line, which is the easiest way to implement)
As danialgoodwin mentioned in the comments, adding the buttonBarStyle to the LinearLayout will show default separators. This is also for api level 11 or higher only.
The important part here, is adding this line to the LinearLayout:
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" style="?android:buttonBarStyle" android:dividerPadding="15dp" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button1" android:layout_gravity="center_vertical" /> <!-- more buttons/views --> </LinearLayout>
You can also adjust the paddings of the view separators with the "dividerPadding" setting.
Button uses the same report, so the spacing between them is the same.
Of course, you can set gradient for the split line.
Original article: http://envyandroid.com/archives/1193/view-separators