android-empty-layout icon indicating copy to clipboard operation
android-empty-layout copied to clipboard

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

Open walfud opened this issue 10 years ago • 4 comments

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.

walfud avatar Apr 15 '15 11:04 walfud

I don't know whether I can commit my change to your repos. however, I did it. image

Wish this view support more projs. If made any trouble, I'm sorry for that.

walfud avatar Apr 15 '15 11:04 walfud

Nice change.@walfud I want use this library to show network error UI. Thx for your code~

ghost avatar May 19 '15 01:05 ghost

Just fork this repo and pull a request~

ghost avatar May 19 '15 01:05 ghost

I did that. @johnwatson5412 The repo: https://github.com/walfud/android-empty-layout.git

walfud avatar May 22 '15 08:05 walfud