Reputation: 1285
The code below is for a ListView with a footer, the problem I am facing is that the lower entries in the ListView are getting overlapped by the footer. So Could you suggest any solution (because I tried a lot and it each situation I am getting the same overlapping result) or some other way to do it. Thanks in advance. I have also posted the code of the footer just in case.
<LinearLayout android:id="@+id/homeParentLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/listV_main"
android:listSelector="@android:color/transparent"/>
<include android:id="@+id/footer" android:layout_height="wrap_content"
layout="@layout/mymenu" android:layout_width="fill_parent"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true">
</include>
</RelativeLayout>
</LinearLayout>
Code for mymenu.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="bottom">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="vertical">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
<ImageView
android:id="@+id/imgSetting"
android:src="@drawable/settings_gear_icon_256"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_marginLeft="10sp"
android:clickable="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
<ImageView
android:id="@+id/imgLogin"
android:layout_width="60dip"
android:src="@drawable/login_lock_256"
android:clickable="true"
android:layout_height="60dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=" "
android:gravity="center"/>
</TableRow>
</TableLayout>
</LinearLayout>
Upvotes: 1
Views: 329
Reputation: 45493
Although a RelativeLayout
generally gives you more flexibility for layout design, in the case of a fairly straightforward layout like this, you can use weights to distribute the screen estate in a similar manner using a LinearLayout
.
Note that the most notable changes below are in the ListView
declaration. The height of '0dp' and the weight of '1' will make the ListView
take up as many space (vertically) as possible, without pushing the footer off the bottom. Effectively, this will bottom-align the footer.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/homeParentLayout"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_height="0dp" android:layout_weight="1"
android:layout_width="fill_parent" android:id="@+id/listV_main"
android:listSelector="@android:color/transparent" />
<include android:id="@+id/footer" android:layout_height="wrap_content"
layout="@layout/mymenu" android:layout_width="fill_parent"
android:layout_gravity="center_horizontal" />
</LinearLayout>
I also took the liberty of removing what appeared to be some left-over tags/attributes from playing around with a RelativeLayout
.
Upvotes: 0
Reputation: 10353
Use a relative layout like this: Declare the relative layout, then declare the footer as the first element. These properties are the important ones for the footer:
android:layout_alignParentBottom="true"
android:id="@+id/footer_id"
Then declare your listView with this property:
android:layout_above="@id/footer_id"
And that should do it.
Upvotes: 2