Tee Tee - 2 months ago 33
Android Question

View.GONE not working properly

I have a GridView of items which i am getting from a web API. I want a "Load more" button to appear once i reach the end of gridview. It works properly until i click the button. The button is supposed to disappear without leaving space but its actually leaving the space.

I get this when i reach the end of the GridView.
enter image description here
When i click the load more button it disappears which is good but leaves space.
Below is my piece of code:
enter image description here

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
Log.v("TestInstallationTaskLst", "onScroll");
int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem==totalItemCount && totalItemCount!=0)
{
loadMoreButton.setVisibility(View.VISIBLE);
}
else
{
loadMoreButton.setVisibility(View.GONE);
}
}

@Override
public void onClick(View view)
{
if (view == loadMoreButton)
{
int offset = assets.size()+1;
new DownloadTask().execute(searchText, offset, LIMIT);
loadMoreButton.setVisibility(View.GONE);
}
}

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main Content View (Must be first child in the DrawerLayout -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_grey_color">

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:indeterminate="true"
android:layout_gravity="center_vertical" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<SearchView android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:queryHint="Search vehicle"/>


<GridView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:verticalSpacing="10dp"
android:horizontalSpacing="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:numColumns="2">
</GridView>

<Button
android:id="@+id/load_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load more"/>

</LinearLayout>


</FrameLayout>
<!-- Navigation Drawer -->
<ExpandableListView
android:id="@+id/gps_menu_drawer"
android:layout_width="@dimen/navigation_bar_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@color/gps_dark_grey"/>



Answer

try Using RelativeLayout

EDITED :

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main Content View (Must be first child in the DrawerLayout -->
<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:indeterminate="true"
        android:layout_centerInParent="true"/>

    <SearchView
        android:id="@+id/searchView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:clickable="true"
        android:queryHint="Search vehicle"/>


    <GridView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/searchView"
        android:layout_centerHorizontal="true"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="20dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:numColumns="2">
    </GridView>

    <Button
        android:id="@+id/load_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Load more"/>

</RelativeLayout>

</FrameLayout>