BP_Phantom 2014-10-15 15:20 采纳率: 0%
浏览 621

android开发中布局怎么把元素之间的空间取消

我想做一个ios的计算器,但是ios计算器之间的button挨在一起用线分开
除了linearlayout之外有没有办法可以做成那个样子呢。我用linearlayout做了一个。但是别的布局不会。

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-02 21:40
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    在Android中,没有直接的方法来实现您所描述的效果(即消除按钮之间空间)。然而,您可以使用一些技巧和方法来模拟这种效果。

    1. 使用LinearLayout:虽然它不能完全模仿iOS中的布局,但它可以帮助您创建一个类似的效果。例如:
    <LinearLayout
        android:orientation="horizontal"
        android:weightSum="3"
        android:padding="5dp">
        <Button
            android:id="@+id/button1"
            android:text="Button 1" />
        <Button
            android:id="@+id/button2"
            android:text="Button 2" />
        <Button
            android:id="@+id/button3"
            android:text="Button 3" />
    </LinearLayout>
    

    这将使三个按钮并排排列,并且它们之间有5dp的空间。

    1. 使用FrameLayout:如果您不希望用户点击按钮时看到空隙,请考虑使用FrameLayout代替LinearLayout。例如:
    <FrameLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        <Button
            android:id="@+id/button1"
            android:text="Button 1" />
    
        <Button
            android:id="@+id/button2"
            android:text="Button 2" />
    
        <Button
            android:id="@+id/button3"
            android:text="Button 3" />
    
    </FrameLayout>
    

    这样,当用户点击这些按钮时,会看到明显的边界。

    请注意,上述示例仅用于说明目的,实际应用中可能需要根据具体需求进行调整。

    评论

报告相同问题?