【问题标题】:Any examples of irregular shaped button layout in Android?Android中不规则形状按钮布局的任何示例?
【发布时间】:2014-12-10 06:35:52
【问题描述】:

您好,我正在寻找在 Android 中制作 UI,我正在考虑将四个圆形按钮以菱形的形式彼此靠近。所以我不能将它们包含在正方形网格中,否则它们会在点击时相互重叠。

谁能给我指出一个具有不规则形状(非方形)按钮的教程或示例代码?

【问题讨论】:

标签: android layout


【解决方案1】:

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>

【讨论】:

  • 如果表格是按钮宽度的 3 倍,那么它只是一个标准网格,按钮之间的空间太大。我希望他们更亲近。例如,此网格中四个单元格中的圆圈i72.photobucket.com/albums/i163/keytotheleyline7/…
  • 然后只需将tablelayout = wrap_content 高度和宽度。我稍后会测试它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-14
相关资源
最近更新 更多