2011-05-01 34 views
1

嗨我正在寻找一个在Android的用户界面,在那里我想把四个圆形按钮放在彼此靠近的钻石形成。所以我不能让它们包含在一个正方形网格中,或者它们会重叠在一起。Android中不规则形状按钮布局的任何示例?

任何人都可以指向一个具有不规则形状(非方形)按钮的教程或示例代码吗?

+0

我知道这是旧的,但找到了解决方案吗?我有一个类似的问题: http://stackoverflow.com/questions/27367068/overlapping-buttons-with-custom-shape – Phil3992 2014-12-09 21:39:48

回答

0

怎么样一个TableLayout只是按住按钮。使用TableLayout作为容器来包装您的按钮。然后将TableLayout锚定到您想要按钮组的位置。

PSUEDOCODE 

<TableLayout 
    android:id="@+id/ButtonContainer" 
    android:layout_width="3XButtonWidth" 
    android:layout_height="3XButtonHeight" 
    android:layout_alignParentBottom="OrWhereYouNeedIt" 
    android:layout_alignParentRight="OrWhereYouNeedIt" 
    > 
    <TableRow 
    android:id="@+id/FirstRow"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
    <ImageButton 
     android:id="@+/TopButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:AnyOtherParams="true"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</TableRow> 
<TableRow 
    android:id="@+id/MiddleRow"> 
    <ImageButton 
     android:id="@+/LeftButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:AnyOtherParams="true"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
    <ImageButton 
     android:id="@+/RightButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:AnyOtherParams="true"/> 
    </TableRow> 
    <TableRow 
    android:id="@+id/LastRow"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
    <ImageButton 
     android:id="@+/BottomButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:AnyOtherParams="true"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</TableRow> 
</TableLayout> 
+0

如果表是3倍的按钮宽度,这只是使它成为一个标准的网格与远按钮之间的空间太大。我希望他们更接近。例如,在这个网格中的四个单元格中的圆圈http://i72.photobucket.com/albums/i163/keytotheleyline7/Shippougrid.jpg – aph 2011-05-01 19:07:14

+0

然后,只需使tablelayout = wrap_content的高度和宽度。我会在稍后测试它。 – Phobos 2011-05-02 04:04:36