将操作栏放在按钮上方的行和两个按钮之间的线上

时间:2014-07-01 07:43:22

标签: android xml android-layout

目前我在两个按钮之间放一条细线并且两条按钮上方的一条线类似于操作栏中的一条线时遇到了一些麻烦。

现在我的按钮看起来像这样:

enter image description here

我想要得到这个:

enter image description here

不完全确定该怎么做。我试图实现这一点,但没有运气:

android how to make some space between buttons and make white line above each of them

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">




    <Button
    android:id="@+id/block_button"
    style="?android:attr/borderlessButtonStyle"
    android:layout_width="170dp"
    android:layout_height="100dp"
    android:layout_weight="1"
    android:drawableLeft="@drawable/ic_action"
    android:gravity="center_horizontal|center_vertical"
    android:text="@string/block_apps"
    android:textSize="20sp"
        android:layout_alignTop="@+id/start_button"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:id="@+id/start_button"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="170dp"
        android:layout_height="100dp"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:drawableLeft="@drawable/ic_timer"
        android:gravity="center_horizontal|center_vertical"
        android:text="@string/start_apps"
        android:textSize="20sp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />





    </RelativeLayout>

2 个答案:

答案 0 :(得分:1)

  

你只需画一条宽度设置为1且高度为match_parent`

的线
           <LinearLayout
            android:layout_marginTop="20sp"
            android:orientation="horizontal"

            android:background="@color/app_yellow"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <Button
                android:gravity="center"

                android:layout_width="0sp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Login"
                android:id="@+id/btnlogin"
                android:layout_gravity="center_vertical"
                android:background="@color/app_yellow"
                android:textColor="@color/white"
                android:onClick="Login"
                android:stateListAnimator="@null"
                />
            <View
                android:background="#ffffff"
                android:layout_marginTop="4sp"
                android:layout_marginBottom="4sp"
                android:layout_width="1sp"
                android:layout_height="match_parent"/>
            <Button
                android:layout_width="0sp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Register"
                android:id="@+id/button7"
                android:background="@color/app_yellow"
                android:layout_gravity="center_vertical"
                android:textColor="@color/white"
                android:onClick="goDash"
                android:stateListAnimator="@null"
                 />

        </LinearLayout>`

答案 1 :(得分:0)

使用FrameLayout作为分隔符。

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#dddddd"
        android:layout_marginBottom="5dp">
    </FrameLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button"
            android:layout_weight="1"/>

        <FrameLayout
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#dddddd"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp">
        </FrameLayout>

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button2"
            android:layout_weight="1"
            />
    </LinearLayout>

</LinearLayout>