Skip to content

Advice: the 'Empty View' should stay in center of list instead of its parent container. #7

Open
@walfud

Description

@walfud

hello, I found a problem while learning your code. see the usage below:
image
then, you add "Empty View" into the parent of mListView (see EmptyLayout.java:463)
You view looks like this:
image
Obviously, I want the picture in center of list view instead of its parent.

image

Now I make a little change at EmptyLayout.java:changeEmptyType(), you can easily understand.

~~~
    // insert views in the root view
    if (!mViewsAdded) {
        RelativeLayout.LayoutParams lp = new LayoutParams(mListView.getWidth(), mListView.getHeight());
        lp.topMargin = mListView.getTop();
        lp.leftMargin = mListView.getLeft();
        RelativeLayout rl = new RelativeLayout(mContext);
        rl.setLayoutParams(lp);
        if (mEmptyView!=null) {
            rl.addView(mEmptyView);
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mEmptyView.getLayoutParams();
            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
            mEmptyView.setLayoutParams(layoutParams);
        }
        if (mLoadingView!=null) {
            rl.addView(mLoadingView);
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mLoadingView.getLayoutParams();
            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
            mLoadingView.setLayoutParams(layoutParams);
        }
        if (mErrorView!=null) {
            rl.addView(mErrorView);
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mErrorView.getLayoutParams();
            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
            mErrorView.setLayoutParams(layoutParams);
        }
        mViewsAdded = true;

        ViewGroup parent = (ViewGroup) mListView.getParent();
        parent.addView(rl);
        mListView.setEmptyView(rl);
    }
~~~

Thanks for your good code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions