Added scroll offset

pull/199/head
M66B 4 years ago
parent e7da93ec32
commit 53a6da1a15

@ -38,7 +38,6 @@ import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
@ -76,7 +75,8 @@ public class FragmentBase extends Fragment {
private boolean finished = false; private boolean finished = false;
private String requestKey = null; private String requestKey = null;
private int scrollTo = 0; private int scrollToResid = 0;
private int scrollToOffset = 0;
private static int requestSequence = 0; private static int requestSequence = 0;
@ -105,13 +105,14 @@ public class FragmentBase extends Fragment {
updateSubtitle(); updateSubtitle();
} }
void scrollTo(int resid) { void scrollTo(int resid, int offset) {
scrollTo = resid; scrollToResid = resid;
scrollToOffset = offset;
scrollTo(); scrollTo();
} }
private void scrollTo() { private void scrollTo() {
if (scrollTo == 0) if (scrollToResid == 0)
return; return;
View view = getView(); View view = getView();
@ -122,11 +123,12 @@ public class FragmentBase extends Fragment {
if (scroll == null) if (scroll == null)
return; return;
final View child = scroll.findViewById(scrollTo); final View child = scroll.findViewById(scrollToResid);
if (child == null) if (child == null)
return; return;
scrollTo = 0; scrollToResid = 0;
final int dy = Helper.dp2pixels(scroll.getContext(), scrollToOffset);
scroll.post(new Runnable() { scroll.post(new Runnable() {
@Override @Override
@ -134,7 +136,10 @@ public class FragmentBase extends Fragment {
Rect rect = new Rect(); Rect rect = new Rect();
child.getDrawingRect(rect); child.getDrawingRect(rect);
scroll.offsetDescendantRectToMyCoords(child, rect); scroll.offsetDescendantRectToMyCoords(child, rect);
scroll.scrollTo(0, rect.top - scroll.getPaddingTop()); int y = rect.top - scroll.getPaddingTop() + dy;
if (y < 0)
y = 0;
scroll.scrollTo(0, y);
} }
}); });
} }

@ -260,7 +260,7 @@ public class FragmentOptions extends FragmentBase {
pager.setCurrentItem(tab); pager.setCurrentItem(tab);
FragmentBase fragment = (FragmentBase) adapter.instantiateItem(pager, tab); FragmentBase fragment = (FragmentBase) adapter.instantiateItem(pager, tab);
fragment.scrollTo(resid); fragment.scrollTo(resid, -48);
menuSearch.collapseActionView(); menuSearch.collapseActionView();
// Blink found text // Blink found text

Loading…
Cancel
Save