android - 如何在两个图像布局之间画线

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

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

我已成功显示四个图像按钮,但无法显示分隔线。在下图中,您可以看到我正在尝试设计的内容:

enter image description here

最佳答案

使用相对布局并首先添加 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>

关于android - 如何在两个图像布局之间画线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12535278/

相关文章:

java - 错误 : 'SDL init failure, reason is: No available video device' when launching AVD

android - 为 ARM :./.libs/libprotoc.so 交叉编译 protobuf 时出错:错误:未定义对“描述符”的引用

android - 如何居中线性布局

AndroidX 在 MultiSelectListPreference 上崩溃

java - 当线性布局在按钮单击上可见时如何向下滚动线性布局 [kotlin]

android - 如何使用 LinearLayout 定位 Button 死点

android - Retrofit 2 无法对正文使用 Delete 标签

android - 添加 Google Fit 距离(DataPoint 超出范围)

Android : How set force device orientation by device type (tablet, 手机)?

java - 即使在对话框显示并关闭后,如何保持底部控制栏始终隐藏?