所以我想做的是在屏幕顶部使用 GridView ,在屏幕下半部分使用表格 View 。我认为这很容易,但显然我错了。是的,我进行了 1 小时的常规搜索,然后在 stackoverflow 上发布了一些内容。
<?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:stretchColumns="1">
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:numColumns="4"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_height="130dp"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="Name:"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:hint="Name"
android:id="@+id/projectName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow>
<TextView
android:text="Start"
android:id="@+id/startText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="Push"
android:id="@+id/startdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="startDate"/>
</TableRow>
<TableRow>
<TextView
android:text="Finish"
android:id="@+id/finishText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/finishdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="finishDate"/>
</TableRow>
</TableLayout>
</LinearLayout>
也许这很简单。也许我应该在早上上床 sleep 。 感谢您的帮助。
最佳答案
1) 添加 android:orientation="vertical"
到 LinearLayout。
2) 对 Grid n Table 布局使用 android:layout_height="fill_parent"
并在 GridLayout 和 TableLayot 中添加 android:layout_weight="0.5"
。这将在屏幕上平分两种布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:stretchColumns="1" android:orientation="vertical">
<GridView android:id="@+id/gridview" android:layout_width="fill_parent"
android:numColumns="4" android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" android:stretchMode="columnWidth"
android:gravity="center" **android:layout_height="fill_parent"**
**android:layout_weight="0.5"** />
<TableLayout android:layout_width="fill_parent"
**android:layout_height="fill_parent"** android:stretchColumns="1"
**android:layout_weight="0.5"**>
其余部分保持不变......
如果您不希望布局平均划分屏幕,您可以尝试 layout_weight 的不同组合,例如 0.4 和 0.6 或 0.8 和 0.2 等。但是如果你使用 layout_height 到一些固定的像素或倾角值,它会在不同的设备屏幕上显示不同......所以我建议使用 layout_weight 参数。
关于android - 在 Android 中添加两个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6607110/