0

I am having a layout which appears like

Screenshot of UI with multiple listview

I want the page to be scrollabale and list view to add dynamically. right now when the data is exceeding the page height, I am not able to scroll the page up.

xml is here

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/buttonlayout"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:background="#1274B9"
        android:gravity="left|top"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/settings"
            android:layout_width="54dp"
            android:layout_height="match_parent"
            android:background="@drawable/backarrow" />

        <ImageView
            android:id="@+id/prevMonth"
            android:layout_width="20dp"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"
            android:clickable="true"
            android:onClick="prevDate"
            android:src="@drawable/calendar_left_arrow_selector" >
        </ImageView>

        <TextView
            android:id="@+id/currentMonth"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_weight="0.6"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF" >
        </TextView>

        <ImageView
            android:id="@+id/nextMonth"
            android:layout_width="20sp"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_marginRight="10sp"
            android:clickable="true"
            android:onClick="nextDate"
            android:src="@drawable/calendar_right_arrow_selector" >
        </ImageView>

        <Button
            android:id="@+id/addEvent"
            android:layout_width="54sp"
            android:layout_height="match_parent"
            android:background="@drawable/check"
            android:onClick="gotomealsactivity" />
    </LinearLayout>

    <!-- Breakfast portion -->

    <RelativeLayout
        android:id="@+id/relativebreakfastheading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/buttonlayout"
        android:background="#1274B9" >

        <TextView
            android:id="@+id/breakfastheading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Breakfast"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/totalcalorieheading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="10dp"
            android:gravity="right"

            android:textColor="#ffffff"
            android:textSize="20sp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativebreakfastlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativebreakfastheading" >

        <ListView
            android:id="@+id/listbreakfast"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

        <TextView
            android:id="@+id/addbreakfast"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/listbreakfast"
            android:layout_centerHorizontal="true"
            android:clickable="true"
            android:gravity="center"
            android:onClick="gotobreakfastactivity"
            android:text="Add Food +"
            android:textStyle="bold" />

        <View
            android:id="@+id/view1"
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/addbreakfast"
            android:background="#ff106510" />
    </RelativeLayout>

    <!-- Lunch portion -->

    <RelativeLayout
        android:id="@+id/relativelunchheading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativebreakfastlist"
        android:background="#1274B9" >

        <TextView
            android:id="@+id/lunchheading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Lunch"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/totalcalorielunchheading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="10dp"
            android:gravity="right"

            android:textColor="#ffffff"
            android:textSize="20sp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativelunchlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativelunchheading" >

        <ListView
            android:id="@+id/listlunch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

        <TextView
            android:id="@+id/addlunch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/listlunch"
            android:layout_centerHorizontal="true"
            android:clickable="true"
            android:gravity="center"
            android:onClick="gotolunchactivity"
            android:text="Add Food +"
            android:textStyle="bold" />

        <View
            android:id="@+id/view2"
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/addlunch"
            android:background="#ff106510" />
    </RelativeLayout>

    <!-- Dinner portion -->

    <RelativeLayout
        android:id="@+id/relativedinnerheading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativelunchlist"
        android:background="#1274B9" >

        <TextView
            android:id="@+id/dinnerheading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Dinner"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/totalcaloriedinnerheading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="10dp"
            android:gravity="right"

            android:textColor="#ffffff"
            android:textSize="20sp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativedinnerlist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativedinnerheading" >

        <ListView
            android:id="@+id/listdinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

        <TextView
            android:id="@+id/adddinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/listdinner"
            android:layout_centerHorizontal="true"
            android:clickable="true"
            android:gravity="center"
            android:onClick="gotodinneractivity"
            android:text="Add Food +"
            android:textStyle="bold" />

        <View
            android:id="@+id/view3"
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/adddinner"
            android:background="#ff106510" />
    </RelativeLayout>

    <!-- Snacks portion -->

    <RelativeLayout
        android:id="@+id/relativesnacksheading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativedinnerlist"
        android:background="#1274B9" >

        <TextView
            android:id="@+id/snacksheading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Snacks"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/totalcaloriesnacksheading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="10dp"
            android:gravity="right"

            android:textColor="#ffffff"
            android:textSize="20sp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativesnackslist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativesnacksheading" >

        <ListView
            android:id="@+id/listsnacks"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

        <TextView
            android:id="@+id/addsnacks"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/listsnacks"
            android:layout_centerHorizontal="true"
            android:clickable="true"
            android:gravity="center"
            android:onClick="gotosnacksactivity"
            android:text="Add Food +"
            android:textStyle="bold" />

        <View
            android:id="@+id/view4"
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/addsnacks"
            android:background="#ff106510" />
    </RelativeLayout>

</RelativeLayout>
Sumeet Rathore
  • 232
  • 3
  • 16

1 Answers1

0

You can find a screen height and compare it to listBottom - coordinate of some of the ListView's bottom and add new ListViews if needed.

int[] coords = {0,0};
list.getLocationOnScreen(coords);
int listBottom = coords[1] + list.getHeight();

Or problem is that you have no ScrollView in layout?

Max Makeichik
  • 227
  • 4
  • 18