Reputation: 49
In an android 4.1 app I'm designing, I'm trying to get my bottom bar that has two buttons to be dynamic, a.k.a. not remain stuck to the bottom of the screen even when I am at the top of the page. I want it to appear only when the user scrolls down to the very end of the page. Right now, no matter how much I try, it remains fixed to the bottom of the screen. I'd really appreciate some help. Thanks.
project_search_list.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1" android:drawSelectorOnTop="false"
/>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:contentDescription="@string/description"
android:gravity="left"
android:scaleType="fitXY" />
<TextView
android:id="@+id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:text="" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/footer" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentBottom="true" style="@android:style/ButtonBar">
<Button android:id="@+id/prev_10_results" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="@string/prev_10_results" />
<Button android:id="@+id/next_10_results" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="@string/next_10_results" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Here's a screen capture. Notice the button bar at the bottom? I want it to appear only when I scroll down to the end of the page.
Upvotes: 3
Views: 2063
Reputation: 1093
This should get you started, check in onscrollstatechanged with row is visible and then take th correct action like toggle or animate the button bar if you use visibility gone the list view will take place on the part where the button bar was before. This way you don't have empty space at the bottom:
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == 0 && mListContent.getLastVisiblePosition() == 0
&& buttonbar.getVisibility() == View.GONE) {
toggleButtonbar();
} else if (mListContent.getLastVisiblePosition() != 0
&& buttonbar.getVisibility() == View.VISIBLE) {
toggleButtonbar();
}
}
Upvotes: 2