如何设置 Table layout bottom to center of screen?
How to set Table layout bottom to center of screen?
对 android 很陌生。我目前在我的第二个 activity 中有一个相对布局,它的顶部有一个 Table 布局,底部有一个列表。我希望屏幕的上半部分用 TableLayout 填充,下半部分用 ListView 填充。
我的问题是我不知道如何对齐它们以适应不同的屏幕尺寸。我正在向 Table 视图动态添加行和列,因此我想确保信息适合其容器。我知道有 "dp" 方法,但我不认为硬编码是最佳答案。
这是我的 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context="hss.quickpool.PoolSheet">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:stretchColumns="*"
android:shrinkColumns="*"
android:id="@+id/tlPool">
</TableLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="170dp"
android:id="@+id/lvBouts"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
我如何确保这两个家伙不会互相重叠?
添加
android:layout_alignParentTop="true"
到TableLayout
和
android:layout_below="@+id/tlPool"
至ListView
。
应该可以了。
对于这种类型的布局,您应该使用线性布局而不是相对布局,并使用权重确保它们都占据屏幕的一半
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation = "vertical"
tools:context="hss.quickpool.PoolSheet">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight = "1"
android:stretchColumns="*"
android:shrinkColumns="*"
android:id="@+id/tlPool">
</TableLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight = "1"
android:id="@+id/lvBouts" />
</LineaserLayout>
对 android 很陌生。我目前在我的第二个 activity 中有一个相对布局,它的顶部有一个 Table 布局,底部有一个列表。我希望屏幕的上半部分用 TableLayout 填充,下半部分用 ListView 填充。
我的问题是我不知道如何对齐它们以适应不同的屏幕尺寸。我正在向 Table 视图动态添加行和列,因此我想确保信息适合其容器。我知道有 "dp" 方法,但我不认为硬编码是最佳答案。
这是我的 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context="hss.quickpool.PoolSheet">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:stretchColumns="*"
android:shrinkColumns="*"
android:id="@+id/tlPool">
</TableLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="170dp"
android:id="@+id/lvBouts"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
我如何确保这两个家伙不会互相重叠?
添加
android:layout_alignParentTop="true"
到TableLayout
和
android:layout_below="@+id/tlPool"
至ListView
。
应该可以了。
对于这种类型的布局,您应该使用线性布局而不是相对布局,并使用权重确保它们都占据屏幕的一半
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation = "vertical"
tools:context="hss.quickpool.PoolSheet">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight = "1"
android:stretchColumns="*"
android:shrinkColumns="*"
android:id="@+id/tlPool">
</TableLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight = "1"
android:id="@+id/lvBouts" />
</LineaserLayout>