如何在两个图像布局之间绘制线条

时间:2012-09-21 17:27:27

标签: android android-layout android-linearlayout android-imageview

我正在尝试创建具有四个按钮的布局。

我设法显示了四个图像按钮,但我无法显示分隔线。在下图中,您可以看到我想要设计的内容:

enter image description here

2 个答案:

答案 0 :(得分:2)

使用相对布局并首先添加View对象以将它们分开(参见下文)。你必须添加你想要的任何其他参数......

<RelativeLayout
    android:layout_width          = "match_parent"
    android:layout_height         = "match_parent">

    <View
        android:id                      = "@+id/vertical_divider"
        android:layout_centerHorizontal = "true"
        android:layout_width            = "1dip"
        android:layout_height           = "match_parent">
    </View>

    <View
        android:id                      = "@+id/horizontal_divider"
        android:layout_centerVertical   = "true"
        android:layout_width            = "match_parent"
        android:layout_height           = "1dip">
    </View>

    <ImageButton
        android:layout_alignParentTop   = "true"
        android:layout_alignParentLeft  = "true"
        android:layout_toLeftOf         = "@id/vertical_divider"
        android:layout_above            = "@id/horizontal_divider"
        android:layout_width            = "match_parent"
        android:layout_height           = "match_parent">
    </ImageButton>

    <ImageButton
        android:layout_alignParentTop   = "true"
        android:layout_alignParentRight = "true"
        android:layout_toRightOf        = "@id/vertical_divider"
        android:layout_above            = "@id/horizontal_divider"
        android:layout_width            = "match_parent"
        android:layout_height           = "match_parent">
    </ImageButton>

    <ImageButton
        android:layout_alignParentBottom = "true"
        android:layout_alignParentLeft   = "true"
        android:layout_toLeftOf          = "@id/vertical_divider"
        android:layout_below             = "@id/horizontal_divider"
        android:layout_width             = "match_parent"
        android:layout_height            = "match_parent">
    </ImageButton>

    <ImageButton
        android:layout_alignParentBottom = "true"
        android:layout_alignParentRight  = "true"
        android:layout_toRightOf         = "@id/vertical_divider"
        android:layout_below             = "@id/horizontal_divider"
        android:layout_width             = "match_parent"
        android:layout_height            = "match_parent">
    </ImageButton>
</RelativeLayout>

答案 1 :(得分:0)

layout_marginBottom="1dip"

中添加layout_marginRight="1dip"Imageviews