如何在 Android 布局中表示这一点

发布于 2024-10-01 00:51:40 字数 304 浏览 1 评论 0原文

我需要表示下图:
alt text

每个 X 都是一个图像按钮。我正在考虑制作三个表格,每个表格一列,并且每个单元格的高度为表格高度的一半。问题是桌子需要能够拉伸或收缩,因为我担心屏幕上的所有内容都显示出来,而桌子是唯一可以改变大小并使整个东西看起来还不错的部分。我遇到的问题是行只与图像按钮一样大。虽然所有图像按钮的大小相同,但尤其是左表和右表,需要在图像按钮周围有一些填充,以使其正常。我会为按钮添加边距,但这解决了我遇到的重塑问题......我认为。有什么建议吗?

I need to represent the following diagram:
alt text

Each X will be an image button. I was thinking of making three tables with one column each and have each cell height be half the height of the table. The problem is that the table needs to be able to stretch or shrink because I am worried about getting everything on the screen and the tables are the only part that can change size and have the entire thing still look ok. The problem I am having is that the rows are only as big as the image buttons. While all the image buttons are the same size, the left and right table in particular, need to have some padding around the image buttons to make it alright. I would add margins to the buttons but that defeats the reshaping problem I am having...I think. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

束缚m 2024-10-08 00:51:40

可能有更好的方法,但下面是实现此目的的一种方法。按钮是否需要拉伸以适应单元格?或者他们只是以内部为中心?假设是后者,这里有一个建议(我对此没有信心,但我相信它应该有效):

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="horizontal"
 >
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:layout_weight="1"
  android:gravity="center"
  >
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable11"
   />
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable12"
   />
 </LinearLayout>

 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:layout_weight="1"
  android:gravity="center"
  >
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable21"
   />
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable22"
   />
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable23"
   />
 </LinearLayout>

 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:layout_weight="1"
  android:gravity="center"
  >
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable11"
   />
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable12"
   />
 </LinearLayout>
</LinearLayout>

不幸的是,我现在没有 Eclipse 来测试它,但这应该接近您所需要的。可能有一种更干净的方法使用RelativeLayout(使用更少的嵌套视图),但这不是我的想法,给你一些开始的东西。

There may be a better way, but below is one way to accomplish this. Do the buttons need to stretch to fit the cells? Or will they just be centered within? Assuming the latter, here's a suggestion (I am not confident on this, but I believe it should work):

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="horizontal"
 >
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:layout_weight="1"
  android:gravity="center"
  >
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable11"
   />
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable12"
   />
 </LinearLayout>

 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:layout_weight="1"
  android:gravity="center"
  >
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable21"
   />
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable22"
   />
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable23"
   />
 </LinearLayout>

 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:layout_weight="1"
  android:gravity="center"
  >
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable11"
   />
  <ImageButton
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"                           
   android:layout_weight="1"
   android:src="@drawable/drawable12"
   />
 </LinearLayout>
</LinearLayout>

I unfortunately don't have Eclipse right now to test this, but this should be close to what you need. There's probably a cleaner way using a RelativeLayout (using fewer nested views) but this is off the top of my head, gives you something to start with.

夏末 2024-10-08 00:51:40

尝试使用网格视图。

Android 开发人员参考链接

蝶舞 2024-10-08 00:51:40

如果您使用 UI 绘图工具(例如 DroidDraw),您可能会更容易将其组合在一起。完成绘图后,应用程序将生成适当的源代码以供您的应用程序使用。

You may have an easier time putting this together if you use a UI drawing tool such as DroidDraw. When you're done with drawing, the application will generate the appropriate source code to use for your app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文