需要Android TableLayout校准方面的帮助吗
我试图使用TableLayout构建计算器布局,但最后两行与布局的其余部分不对齐。我的布局XML有问题吗 我想用HTML(需要Android TableLayout校准方面的帮助吗,android,tablelayout,Android,Tablelayout,我试图使用TableLayout构建计算器布局,但最后两行与布局的其余部分不对齐。我的布局XML有问题吗 我想用HTML(和colspan或rowspan)更容易实现,所以我应该试着将其转换为Web视图吗 代码如下:() 您的最终表格行有三个单元格(即直接子单元格)。其余的有四个。因此,它们不会对齐,除非您在其中的某个位置放置一个android:layout\u span属性,以指示哪个单元格正在吸收第四个单元格。显然“=”按钮占用的空间比您预期的要多。尝试调整“=”按钮的layout_wei
和colspan
或rowspan
)更容易实现,所以我应该试着将其转换为Web视图吗
代码如下:()
您的最终表格行
有三个单元格(即直接子单元格)。其余的有四个。因此,它们不会对齐,除非您在其中的某个位置放置一个android:layout\u span
属性,以指示哪个单元格正在吸收第四个单元格。显然“=”按钮占用的空间比您预期的要多。尝试调整“=”按钮的layout_weight参数。“但最后两行与布局的其余部分不对齐”--我从这里看不到您的屏幕。你能发布你所看到的屏幕截图吗?如果你有一个模型来展示你想要达到的目标,那就更好了。primalpop,我把它的权重改为0,现在我做到了。有没有一种方法可以让表格单元格覆盖多个行/列而不使用嵌套的LinearLayouts?Commonware是原始版本,也是当前版本。我只使用嵌套线性布局制作了类似的布局。对我来说,它更容易使用,尽管它可能比相对布局重一些。我将包含0、1和2的“单元格”设置为跨越两个单元格,并将等号重新设置为权重1,它就像一个符咒!谢谢
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<TableLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:stretchColumns="*">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="@+id/Button08"
android:textSize="16pt"
android:text="^"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="wrap_content" />
<Button
android:id="@+id/Button09"
android:text="÷"
android:textSize="16pt"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_width="wrap_content" />
<Button
android:id="@+id/Button10"
android:text="×"
android:textSize="16pt"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_width="wrap_content" />
<Button
android:id="@+id/Button11"
android:textSize="16pt"
android:text="-"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="wrap_content" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1">
<Button
android:id="@+id/Button01"
android:text="7"
android:textSize="16pt"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<Button
android:layout_height="wrap_content"
android:textSize="16pt"
android:text="4"
android:id="@+id/Button05"
android:layout_weight="1"
android:layout_width="fill_parent" />
</LinearLayout>
<LinearLayout
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="fill_parent">
<Button
android:id="@+id/Button02"
android:layout_height="wrap_content"
android:text="8"
android:textSize="16pt"
android:layout_weight="1"
android:layout_width="fill_parent" />
<Button
android:layout_height="wrap_content"
android:textSize="16pt"
android:text="5"
android:id="@+id/Button06"
android:layout_weight="1"
android:layout_width="fill_parent" />
</LinearLayout>
<LinearLayout
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="fill_parent">
<Button
android:id="@+id/Button03"
android:text="9"
android:textSize="16pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:textSize="16pt"
android:text="6"
android:id="@+id/Button07"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<Button
android:id="@+id/Button04"
android:text="+"
android:textSize="16pt"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="2">
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/Button02"
android:textSize="16pt"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="1" />
<Button
android:textSize="16pt"
android:id="@+id/Button06"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="2" />
</LinearLayout>
<Button
android:id="@+id/Button01"
android:layout_height="wrap_content"
android:textSize="16pt"
android:layout_weight="1"
android:layout_width="fill_parent"
android:text="0" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1">
<Button
android:id="@+id/Button03"
android:textSize="16pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
<Button
android:textSize="16pt"
android:id="@+id/Button07"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="." />
</LinearLayout>
<Button
android:id="@+id/Button04"
android:textSize="16pt"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="=" />
</TableRow>
</TableLayout>
</LinearLayout>