将 TableLayout 嵌套在 LinearLayout 中 - 这可能吗?
我想要生成一个如下所示的 Android 屏幕布局:
Label Text Field
Label Text Field
Label Text Field
-----Button-------
-----TextField----
也就是说,我想要在顶部有一个 TableLayout,在表格布局下方有许多项目(主要是这样我可以强制这些项目位于底部)屏幕)。我尝试按照下面的代码嵌套它们,但底部的项目似乎没有出现。
有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:stretchColumns="1"
android:shrinkColumns="1" android:layout_height="wrap_content" android:layout_gravity="center_vertical">
<TableRow>
<TextView android:text="Latitude:"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView android:id="@+id/latitude"
android:text="Not available"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</TableRow>
<TableRow>
<TextView android:text="Longitude:"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView android:id="@+id/longitude"
android:text="Not available"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</TableRow>
<TableRow>
<TextView android:text="Altitude:"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView android:id="@+id/altitude"
android:text="Not available"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</TableRow>
<TableRow>
<TextView android:text="Accuracy:"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView android:id="@+id/accuracy"
android:text="Not available"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</TableRow>
</TableLayout>
<Button android:id="@+id/save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save"/>
<TextView android:text="Test"/>
</LinearLayout>
I want to produce an Android screen layout that looks something like the following:
Label Text Field
Label Text Field
Label Text Field
-----Button-------
-----TextField----
That is, I want to have a TableLayout at the top, with a number of items underneath the table layout (mainly so I can force these items to be at the bottom of the screen). I have tried to nest them as in the code below, but the items at the bottom don't seem to appear.
Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:stretchColumns="1"
android:shrinkColumns="1" android:layout_height="wrap_content" android:layout_gravity="center_vertical">
<TableRow>
<TextView android:text="Latitude:"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView android:id="@+id/latitude"
android:text="Not available"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</TableRow>
<TableRow>
<TextView android:text="Longitude:"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView android:id="@+id/longitude"
android:text="Not available"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</TableRow>
<TableRow>
<TextView android:text="Altitude:"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView android:id="@+id/altitude"
android:text="Not available"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</TableRow>
<TableRow>
<TextView android:text="Accuracy:"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView android:id="@+id/accuracy"
android:text="Not available"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</TableRow>
</TableLayout>
<Button android:id="@+id/save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save"/>
<TextView android:text="Test"/>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的表格布局中
也为底部按钮添加这些,并且文本视图添加固定高度。如果您的表格需要更多空间
然后把它放在scrollView之间
in your table layout add these
also for the bottom button and and text view add fixed height.If your table needs more space
then put it between scrollView
将表格的权重设置为“1”,将高度设置为“0dp”。
Set the weight of the table to "1", and the height to "0dp".
对于文本字段,您必须使用 EditText 代替 TextView,并将
android:layout_height
和android:layout_width
添加到应用程序中使用的每个小部件。For textfield you have to use EditText in place of TextView and add
android:layout_height
andandroid:layout_width
to each widget used in your application.