Created
July 21, 2014 15:43
-
-
Save marinat/5e68f28fa17ac1de3b2e to your computer and use it in GitHub Desktop.
Scroll
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
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