Created
April 22, 2014 06:30
-
-
Save yrom/11167376 to your computer and use it in GitHub Desktop.
A hack to add the translation to the action bar (excerpt from https://github.com/umano/AndroidSlidingUpPanel/tree/master/demo)
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
public void setActionBarTranslation(float y) { | |
// Figure out the actionbar height | |
int actionBarHeight = 0; | |
TypedValue tv = new TypedValue(); | |
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { | |
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics()); | |
} | |
// A hack to add the translation to the action bar | |
ViewGroup content = ((ViewGroup) findViewById(android.R.id.content).getParent()); | |
int children = content.getChildCount(); | |
for (int i = 0; i < children; i++) { | |
View child = content.getChildAt(i); | |
if (child.getId() != android.R.id.content) { | |
if (y <= -actionBarHeight) { | |
child.setVisibility(View.GONE); | |
} else { | |
child.setVisibility(View.VISIBLE); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
child.setTranslationY(y); | |
} else { | |
com.nineoldandroids.view.animation.AnimatorProxy.wrap(child).setTranslationY(y); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { child.setTranslationY(y); } else { com.nineoldandroids.view.animation.AnimatorProxy.wrap(child).setTranslationY(y); }
是多余的,sdk<11 根本就木有actionbar