【发布时间】:2011-04-22 15:32:57
【问题描述】:
编辑: TableLayout 不能正常工作吗?我看到你们中的大多数人都说使用相对布局,而跳过 tableview?
我试图摆脱数据 1 和数据 2 之后的空间。如果我在没有 TableLayout 的情况下放置相同的 XML 代码,那么它看起来没问题。我要改变什么?
带有“100”的第三行我想要右侧的 2 个条目文本视图。我已经尝试了我能想到的一切,但它不会向右走。我删除了第二个 textview 以查看是否有帮助,但没有太大区别。
谁能告诉我我做错了什么?谢谢!
这是 XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout android:layout_width="fill_parent"
android:stretchColumns="*" android:layout_height="fill_parent"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="6px">
<TableRow style="@style/FormRows" android:layout_marginTop="15sp">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginLeft="5px"
android:layout_span="3" android:layout_weight="1" android:text="Save"
android:id="@+id/dgSave" />
</TableRow>
<TableRow style="@style/FormRows">
<TextView android:layout_width="70sp"
android:layout_height="wrap_content" android:textSize="16sp"
android:layout_weight="1" android:text="Data 1" />
<Spinner android:id="@+id/dgData0" android:layout_weight="2"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<EditText android:text="100" android:selectAllOnFocus="true"
android:imeOptions="actionNext" android:numeric="integer"
android:width="100sp" android:id="@+id/dgWarn0" android:gravity="right"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_gravity="right" android:layout_span="2" />
<EditText android:text="100" android:selectAllOnFocus="true"
android:imeOptions="actionNext" android:numeric="integer"
android:width="100sp" android:id="@+id/dgWarn1" android:gravity="right"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_gravity="right" android:layout_span="2" />
</LinearLayout>
</TableRow>
<TableRow style="@style/FormRows">
<TextView android:layout_width="70sp"
android:layout_height="wrap_content" android:textSize="16sp"
android:layout_weight="1" android:text="Data 2" />
<Spinner android:id="@+id/dgData1" android:layout_weight="2"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</ScrollView>
谢谢!寻求帮助!!! 标记
【问题讨论】:
-
你应该使用表格布局吗?因为我们可以使用相对布局来实现这个布局。
-
我认为Data后面的空格是因为
android:layout_weight="1",但你说你可以接受这个xml w/oTableLayout... -
我不知道为什么,可能是因为我刚刚发现自己学习了 LinearLayout 和 RelativeLayout 并一遍又一遍地重复使用它们,但我从来没有使用过 Table Layout...从来没有用过为了它。使用相对布局将非常容易。将 Save 按钮放在您想要的位置,将 Spinners 右边缘与保存按钮的右边缘对齐,将 Data 标签放在 Spinners 的右侧,等等......应该很容易。
-
您应该查看 Google 的教程,看看他们如何使用 TableLayout:developer.android.com/guide/tutorials/views/…
-
你能分享一个你想要的布局的模型吗? @Venkatesh 提到使用
RelativeLayout解决问题。我完全同意这一点,对于这种复杂的视图来说,它要方便得多。TableLayout是为表格 (...) 创建的,使用RelativeLayout您还可以节省布局数量,因此它将是您的最佳选择。
标签: android xml scrollview tablelayout