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

[Feature Request] Make the open item fully visible when at the bottom #25

Open
naddaf opened this issue Apr 5, 2013 · 8 comments
Open

Comments

@naddaf
Copy link
Contributor

naddaf commented Apr 5, 2013

Hi.
Thanks for creating this library. The feature I am asking for is the following: when an item is at the bottom of the page, clicking on that will expand the item but the expanded view is not visible (since the main item was at the bottom) and user has to scroll to make it visible. I think it would be nice to automatically scroll the list slightly to bring the expanded view into the visible area in this case.

Thanks.

@JesseFarebro
Copy link
Contributor

I've noticed this as well I will take a look and see what I can do today. Thanks for the suggestion.

@tjerkw
Copy link
Owner

tjerkw commented Apr 5, 2013

Indeed I know about the issue but didn't have an easy fix at hand.
On Apr 5, 2013 7:17 PM, "Jesse Farebrother" [email protected]
wrote:

I've noticed this as well I will take a look and see what I can do today.
Thanks for the suggestion.


Reply to this email directly or view it on GitHubhttps://github.com//issues/25#issuecomment-15968793
.

@JesseFarebro
Copy link
Contributor

I just tried testing this out with posting a delayed Handler for the animation duration then setting the selection on the listview to the position which automatically makes the view visible without the need to scroll down. It look's very jagged though I'm trying to find a better solution. What did you try @tjerkw ?

@javaguy44
Copy link

Just saw this myself -- was about to submit an issue...but see it's taken care of.

@naddaf
Copy link
Contributor Author

naddaf commented Apr 16, 2013

I went ahead and played with the library and I made some changes to accommodate what I had originally asked, at least to a degree that I am satisfied.

Here is a list of changes I made:

  1. I changed the minSdk to 8. This was required for an api that I am using below. For me, that wasn't an issue at all since devices with lower api version are old enough that I don't bother at all; your millage may be different.
  2. [all other changes are in AbstractSlideExpandableListAdapter]
    /* This points to the listview */

    private ViewGroup parent;
  1. In getView(..), initialize the parent variable:
this.parent = viewGroup;
  1. Update animateView() by adding a listener to capture the end of animation and performing the scroll, if needed:
    private void animateView(final View target, final int type) {
        Animation anim = new ExpandCollapseAnimation(
                target,
                type
        );
        anim.setDuration(getAnimationDuration());
        anim.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {}

            @Override
            public void onAnimationRepeat(Animation animation) {}

            @Override
            public void onAnimationEnd(Animation animation) {
                if (type == ExpandCollapseAnimation.EXPAND) {
                    if (parent instanceof ListView) {
                        ListView listView = (ListView) parent;
                        int movement = target.getBottom();
                        Rect r = new Rect();
                        boolean visible = target.getGlobalVisibleRect(r);
                        Rect r2 = new Rect();
                        listView.getGlobalVisibleRect(r2);
                        if (!visible) {
                            listView.smoothScrollBy(movement, 1000);
                        } else {
                            if (r2.bottom == r.bottom) {
                                listView.smoothScrollBy(movement, 1000);
                            }
                        }
                    }
                }

            }
        });
        target.startAnimation(anim);
    }

Hope that helps,
Ali.

@tjerkw
Copy link
Owner

tjerkw commented Apr 16, 2013

Hey Naddaf that looks like a good solution. Could you create a pull request? You could solve the dependency on android 8 with some java reflection as explained here: http://android-developers.blogspot.nl/2009/04/backward-compatibility-for-android.html

@thisisfaye
Copy link

Thanks, work like a charm!

@JesseFarebro
Copy link
Contributor

Just flagging this to be closed as this has been resolved with commit 8bb3591a43ca7c071dce18f5d2cc5b75145f7da2

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

No branches or pull requests

5 participants