【问题标题】:Android: aligning labels in formsAndroid:在表单中对齐标签
【发布时间】:2012-02-18 02:09:22
【问题描述】:

创建像(比如说)这样的表单布局的最简单方法是什么:

.-----------------------------------------------.
|          First Field [    (EditText)    ]     |
|     Some Other field [    (EditText)    ]     |
|        A Third Field [    (EditText)    ]     |
.-----------------------------------------------.

我的 Android 有点生疏,不知道如何正确使用它 =(.

详情:

  1. 整个事物在它的容器中居中。

  2. 标签彼此水平右对齐,并与各自的输入框垂直居中对齐(尽管我无法在上面的纯文本中表示)

  3. 输入框大小都一样。

如果 EditTexts 可以缩小或增长到最大宽度,则加分,保持布局如上 :D 以便在没有丑陋的超大输入的情况下处理方向变化。

【问题讨论】:

  • 查看链接以获取更多相关信息qustion

标签: android android-layout


【解决方案1】:

试试这个布局,

对于这种设计,您应该始终考虑使用 TableLayout 而不是 RelativeLayout,这样您就可以轻松地动态添加任意数量的行。

<TableLayout
            android:id="@+id/mainTable"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dip"
            android:layout_marginRight="5dip"
            android:paddingLeft="3dip"
            android:paddingRight="3dip"
            android:shrinkColumns="1"
            android:stretchColumns="*"
            android:visibility="gone" >

            <TableRow>

                <TextView
                    style="@style/ds_20_b_darkgray"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Label1: " >
                </TextView>

                <EditText
                    android:id="@+id/editT1"
                    style="@style/ds_20_b_black"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right" >
                </EditText>
            </TableRow>

            <TableRow>

                <TextView
                    style="@style/ds_20_b_darkgray"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Label2: " >
                </TextView>

                <EditText
                    android:id="@+id/editT2"
                    style="@style/ds_20_b_black"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right" >
                </EditText>
            </TableRow>
      </TableLayout> 

您可能需要将整个表格布局放在线性布局或相对布局中,并将表格布局置于中心并根据需要调整边距。

如果这不符合您的要求,我可以修改它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2019-04-29
    • 2013-09-07
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多