Reputation: 2500
Quite new to android. I currently have a relative layout in this second activity of mine with the top of it holding a Table Layout and the bottom a list. I want the top half of the screen to be filled with the TableLayout and the Bottom half with the ListView.
My problem is I don't know how to align them so that they fit with different screen sizes. I am dynamically adding rows & columns to the Table view, so I want to make sure that the information fits in its container. I know there's the "dp" method, but I don't feel like hardcoding is the best answer.
Here's my 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>
How do I make sure these two guys don't over lap each other?
Upvotes: 0
Views: 867
Reputation: 13405
for this type of layout you should be using a linear layout not a relative one, and use weights to make sure they both take up half the screen
<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>
Upvotes: 1
Reputation: 1563
Add
android:layout_alignParentTop="true"
to TableLayout
and
android:layout_below="@+id/tlPool"
to ListView
.
That should do it.
Upvotes: 1