[英]how to move an android view 20 dp up?
我想從下往上看
我需要支持Min API 8,並且無法添加外部庫
如果出現以下情況,我該怎么做:
1)我想在2秒內將其移動20 dps嗎?
2)我想將其從其原始位置移動到其左上角移動為視圖高度的兩倍?
這是我的代碼:
public static void slideTooltip(final LinearLayout toolTipLayout) {
TranslateAnimation layoutTranslateAnimation =
new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0F, Animation.RELATIVE_TO_SELF, 1.0F,
Animation.RELATIVE_TO_SELF, 2.0F, Animation.RELATIVE_TO_SELF, 1.0F);
layoutTranslateAnimation.setDuration(10 * 1000);
layoutTranslateAnimation.setFillAfter(true);
layoutTranslateAnimation.setInterpolator(new DecelerateInterpolator());
final AlphaAnimation alphaAnimation = new AlphaAnimation(0.2F, 1.0F);
alphaAnimation.setDuration(10 * 1000);
layoutTranslateAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
toolTipLayout.startAnimation(alphaAnimation);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
});
toolTipLayout.startAnimation(layoutTranslateAnimation);
}
但是我只看到小的而快速的視圖跳轉。 我想念什么?
我實際上會使用ViewPropertyAnimator :
// start 20 pixels down and with 0.2 alpha
toolTipLayout.setTranslationY(20);
toolTipLayout.setAlpha(0.2);
// animate up and to full alpha.
toolTipLayout.animate().translationY(0).alpha(1).setDuration(10*1000).start();
如果您需要支持API12之前的Android設備,請使用http://nineoldandroids.com包裝器庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.