Skip to content

Instantly share code, notes, and snippets.

@jankovd
Created February 9, 2016 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jankovd/19ef35efd1f00e9213fa to your computer and use it in GitHub Desktop.
Save jankovd/19ef35efd1f00e9213fa to your computer and use it in GitHub Desktop.
Workaround for Popup anchor scroll issue tracked at https://code.google.com/p/android/issues/detail?id=135439
import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
/**
* Single purpose TextView to be used as a Popup anchor while it is a child of a scrolling
* container. When a support-v4 popup is shown with an anchor that is inside a scrolling container,
* the observed behaviour is that the container is scrolled so the anchor is at the top of the
* container and fully visible.
* <p>What we do here is {@linkplain #requestRectangleOnScreen consume the request} that would
* result is the container being scrolled.
* <p>Tracked here <a href="https://code.google.com/p/android/issues/detail?id=135439">b/135439</a>
*/
public class PopupAnchorTextView extends AppCompatTextView {
public PopupAnchorTextView(Context context) {
super(context);
}
public PopupAnchorTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PopupAnchorTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) {
return false;
}
}
@ferrannp
Copy link

ferrannp commented Apr 7, 2016

Hi! Thanks for this, it works! One thing I noticed thought, if you scroll and make your anchor partially visible (from the bottom) and you click on it, then the popup will cover some part of the bottom bar (the one with the back button, etc). Do you know if that is a bug or would be intended to happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment