-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?