Skip to content

Instantly share code, notes, and snippets.

@marinat
Created July 21, 2014 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinat/5e68f28fa17ac1de3b2e to your computer and use it in GitHub Desktop.
Save marinat/5e68f28fa17ac1de3b2e to your computer and use it in GitHub Desktop.
Scroll
package com.example.wwwithscrolltest;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.EditText;
import android.widget.ScrollView;
public final class CustomScrollView extends ScrollView {
public EditText title;
public CustomScrollView(Context context) {
super(context);
}
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
Log.d("SCROLL", "t = " + t + " oldT = " + oldt);
super.onScrollChanged(l, t, oldl, oldt);
if (t < 0)
return;
if (t > oldt) {
if (title.getY() - (t - oldt) / 2 > -title.getHeight())
title.setY(title.getY() - (t - oldt) / 2);
else
title.setY(-title.getHeight());
} else if (t < oldt) {
if (title.getY() + (oldt - t) / 2 < 0)
title.setY(title.getY() + (oldt - t) / 2);
else
title.setY(0);
}
if (t == 0 && oldt == 0)
title.setY(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment