【问题标题】:How to represent this in Android Layout如何在 Android 布局中表示这一点
【发布时间】:2010-11-06 03:07:59
【问题描述】:

我需要表示下图:

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

【问题讨论】:

    标签: android tablelayout


    【解决方案1】:

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

    <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 可能有一种更简洁的方法(使用更少的嵌套视图),但这不是我的想法,可以让您开始。

    【讨论】:

    • 这实际上看起来是个好主意。我会试一试,然后和你一起回来。谢谢
    • 我不得不使用 RelativeLayout 作为持有图像按钮而不是线性布局的子元素,并且还在图像按钮上设置了 align_vertical=true 但这有效。谢谢
    • 太棒了,感谢您的后续修复,很高兴它对您有用!
    【解决方案2】:

    尝试使用网格视图。

    Link to android developer reference

    【讨论】:

      【解决方案3】:

      如果您使用诸如DroidDraw 之类的 UI 绘图工具,您可能会更容易将这些放在一起。完成绘图后,应用程序将生成适当的源代码以供您的应用程序使用。

      【讨论】:

      • 是的,但不要使用绝对布局 lululul
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多