Search code examples
androidandroid-listfragment

Android: ListFragment display blank space


I have a ListView (inside a ListFragment) loading data with the help of a LoaderManager, to which I attach a headerView and a footerView. My problem is that after doing that, it is displaying a lot of blank space (like almost an entire screen) after the footer is displayed. Some code from my ListFragment:

public class NewsDetailsFragment extends ListFragment implements
    LoaderManager.LoaderCallbacks<Cursor> {

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (getArguments().containsKey(Const.ARG_ITEM_ID)) {
        mId = getArguments().getLong(Const.ARG_ITEM_ID);
        getLoaderManager().initLoader(NEWS_DETAILS_LOADER_ID, null, this);
        getLoaderManager().initLoader(COMMENTS_LOADER_ID, null, this);
    }
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mCommentsAdapter = new CommentsListAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.frag_news_details_comments,
            container, false);

    return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mHeaderView = LayoutInflater.from(getActivity()).inflate(
            R.layout.header, getListView(), false);
    mFooterView = LayoutInflater.from(getActivity()).inflate(
            R.layout.footer, getListView(), false);

    setUI();
    setAction();
    if (mHeaderView != null) {
        getListView().addHeaderView(mHeaderView);
    }
    if (mFooterView != null) {
        getListView().addFooterView(mFooterView);
    }
    setListAdapter(mCommentsAdapter);

}

Obviously, this is not the entire code from my ListFragment class, but the other stuff is mostly related to how the data is being manipulated (Loader Callbacks and others). If there is a need to add full code in order to be able to get the correct answer, I will add it on demand.

As for a general idea of how the screen should look like, the header displays some data about the article (which contains a bunch of TextViews, ImageViews and a Webview), the ListView displays comments on this article (if there are any), and the footer displays a form with writing a comment.

LE: This is how it looks like:

Screenshot1

LE2: This screenshot shows how headerView and footerView are limited. headerView ends at "0 comments on this post:" and after that comes the footerView. In between these two, should be displayed the list of comments (if there are any)

Screenshot2

LE3: To make myself even more clear: I will display the wrong (red), and right (green) way it should be displayed. Screenshot3


Solution

  • Turns out I had this background on footerView (the same of the ListView), just to test if everything looked fine, with textColor and stuff, and I forgot to remove it afterwards. Then it took its height, which was larger than the form in the footer, thus creating the empty space. Sry to have bothered your eyes with such stupidity.