Created
November 27, 2013 05:59
-
-
Save goodev/7671306 to your computer and use it in GitHub Desktop.
初始化 ActionBar 图标 并跟随 ListView 来缩放和移动图标
This file contains hidden or 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
private ImageView getActionBarIconView() { | |
return (ImageView) findViewById(android.R.id.home); | |
} | |
ActionBar actionBar = getActionBar(); | |
actionBar.setIcon(R.drawable.ic_transparent); | |
mListView.setOnScrollListener(new AbsListView.OnScrollListener() { | |
@Override | |
public void onScrollStateChanged(AbsListView view, int scrollState) { | |
} | |
@Override | |
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { | |
float ratio = clamp(mHeader.getTranslationY() / mMinHeaderTranslation, 0.0f, 1.0f); | |
//move & scale | |
interpolation = mAccelerateDecelerateInterpolator.getInterpolation(ratio); | |
View actionBarIconView = getActionBarIconView(); | |
getOnScreenRect(mRect1, mHeaderLogo); | |
getOnScreenRect(mRect2, actionBarIconView); | |
float scaleX = 1.0F + interpolation (mRect2.width() / mRect1.width() – 1.0F); | |
float scaleY = 1.0F + interpolation (mRect2.height() / mRect1.height() – 1.0F); | |
float translationX = 0.5F (interpolation (mRect2.left + mRect2.right – mRect1.left – mRect1.right)); | |
float translationY = 0.5F (interpolation (mRect2.top + mRect2.bottom – mRect1.top – mRect1.bottom)); | |
mHeaderLogo.setTranslationX(translationX); | |
mHeaderLogo.setTranslationY(translationY – mHeader.getTranslationY()); | |
mHeaderLogo.setScaleX(scaleX); | |
mHeaderLogo.setScaleY(scaleY); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment