Skip to content

Instantly share code, notes, and snippets.

@yrom
Created April 22, 2014 06:30
Show Gist options
  • Save yrom/11167376 to your computer and use it in GitHub Desktop.
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)
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);
}
}
}
}
}
@yrom
Copy link
Author

yrom commented Apr 22, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment