I want to make a customized separators between buttons in my button bar, I put that button bar in a HorizontalScrollView
, I had used two different ways to do that and both didn't work, The first one is placing a View
between each two buttons like that:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="top"
style="@android:style/ButtonBar"
android:background="@drawable/released" >
<Button
android:id="@+id/Main"
android:layout_width="120dp"
android:layout_height="50dp"
android:background="@android:color/transparent"
android:textColor="@android:color/white"
android:textStyle="bold"
android:text="@string/main"/>
<View android:layout_height="fill_parent"
android:layout_width="2px"
android:background="@drawable/separators"/>
<Button
android:id="@+id/HomeView"
android:layout_width="120dp"
android:layout_height="50dp"
android:background="@android:color/transparent"
android:textColor="@android:color/white"
android:textStyle="bold"
android:layout_toRightOf="@+id/Main"
android:text="@string/homeview" />
/! declaring the rest butttons and views!/
</RelativeLayout>
but when making that i got only one separator placed in the beginning in the button bar before all of the buttons.
The second one is to make a divider
file and using the divider option in my main.xml like that:
<LinearLayout
android:id="@+id/buttonbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="top"
android:divider="@drawable/divider"
android:dividerPadding="12dip"
android:showDividers="middle"
style="@android:style/ButtonBar"
android:background="@drawable/released" >
/! declaring buttons !/
</LinearLayout>
and divider.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="2dip" />
<solid android:color="@drawable/separators" />
</shape>
where separators
is a gradient color,
but this way gives me that error:
java.lang.NullPointerException
at com.android.layoutlib.bridge.impl.RenderSessionImpl.getDefaultProperties(RenderSessionImpl.java:1476)
at com.android.layoutlib.bridge.BridgeRenderSession.getDefaultProperties(BridgeRenderSession.java:68)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.ViewHierarchy.getDefaultProperties(ViewHierarchy.java:710)
at com.android.ide.eclipse.adt.internal.editors.layout.properties.XmlProperty.getStringValue(XmlProperty.java:209)
at com.android.ide.eclipse.adt.internal.editors.layout.properties.XmlProperty.getValue(XmlProperty.java:221)
at com.android.ide.eclipse.adt.internal.editors.layout.properties.BooleanXmlPropertyEditor.paint(BooleanXmlPropertyEditor.java:52)
at org.eclipse.wb.internal.core.model.property.table.PropertyTable.drawProperty(PropertyTable.java:1309)
at org.eclipse.wb.internal.core.model.property.table.PropertyTable.drawContent(PropertyTable.java:1151)
at org.eclipse.wb.internal.core.model.property.table.PropertyTable.handlePaint(PropertyTable.java:1094)
at org.eclipse.wb.internal.core.model.property.table.PropertyTable.access$200(PropertyTable.java:64)
at org.eclipse.wb.internal.core.model.property.table.PropertyTable$3.handleEvent(PropertyTable.java:187)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1081)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
at org.eclipse.swt.widgets.Composite.WM_PRINTCLIENT(Composite.java:1667)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4673)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:340)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4977)
at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2443)
at org.eclipse.swt.widgets.Button.callWindowProc(Button.java:343)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4706)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4990)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2549)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
Regarding your seperator placement between the buttons, as you're using RelativeLayout
you'll need to mention exactly where do you want the seperator to be placed. Replacing the seperator View
in your first layout with the below will give you the desired result:-
<View android:id="@+id/separator"
android:layout_height="fill_parent"
android:layout_toRightOf="@+id/Main"
android:layout_width="2px"
android:background="@drawable/separators"/>
and also make the following change in the HomeView
button
<Button
android:id="@+id/HomeView"
android:layout_width="120dp"
android:layout_height="50dp"
android:background="@android:color/transparent"
android:textColor="@android:color/white"
android:textStyle="bold"
android:layout_toRightOf="@+id/Separator"
android:text="@string/homeview" />