6

我制作了一个自定义按钮栏,如此所述。

现在,我想在第一个和第二个按钮之间以及第二个和第三个按钮之间添加一个分隔符。我的按钮栏定义如下:

<LinearLayout
            android:id="@+id/buttonBar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/buttonbarstyle"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal"
            >
            <ImageButton
                android:id="@+id/buttonBarImageButton1" 
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/copy"
                android:padding="2dip"
                android:background="@drawable/buttonbar_background_selector"
                android:layout_gravity="center_vertical"
            />              
            <ImageButton 
                android:id="@+id/buttonBarImageButton2"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/options"
                android:padding="2dip"
                android:background="@drawable/buttonbar_background_selector"
                android:layout_gravity="center_vertical"
            />              
            <ImageButton
                android:id="@+id/buttonBarImageButton3" 
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/media_play"
                android:padding="2dip"
                android:background="@drawable/buttonbar_background_selector"
                android:layout_gravity="center_vertical"
            />              
        </LinearLayout>

这个任务看起来很简单,但我找不到一个好的方法来完成它。它应该在每个按钮之间有一个灰色的分隔符,所以它看起来有点像这样

我相信这很容易,请指出正确的方向。

4

3 回答 3

31

把它放在每个按钮之间。

<View android:layout_height="fill_parent"
    android:layout_width="2px"
    android:background="#90909090"/>

应该给你一个细长的灰色垂直条。

于 2011-02-19T14:39:02.160 回答
7

你甚至可以通过 fill_parent 放置一个形状很好的分隔符并添加 marginTop|Bottom

  <View
        android:layout_width="1dp"
        android:layout_height="fill_parent"
        android:layout_marginBottom="7dp"
        android:layout_marginTop="7dp"
        android:background="@color/dark_grey" />
于 2012-07-10T15:34:57.210 回答
1

Adding a separator line view is a choice but instead of adding multiple views you can simply set the background of your buttonBar layout greyish and give margin to your buttons from each other. This way views will be separated and background of buttonBar will look like a separator.

于 2016-12-08T05:56:27.573 回答