Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

walfud
Copy link

@walfud walfud commented Apr 29, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant