final int pos = position;
Animation ani = new Animation()
{
@Override protected void applyTransformation(float interpolatedTime, Transformation t)
{
int iPagerPageCount = (int)Math.round(Math.ceil((aryGroupIdx.size()*1.0)/(4*1.0)));
int iDeviceWidth = lib_device.getDeviceWidth(photo_send2_activity.this);
int iWidth = iDeviceWidth - lib_common.getPixelValueOfDp(photo_send2_activity.this, 20);
((LinearLayout.LayoutParams)ivScroll.getLayoutParams()).leftMargin = pos * (iWidth / iPagerPageCount);
((LinearLayout.LayoutParams)ivScroll.getLayoutParams()).width = iWidth / iPagerPageCount;
ivScroll.requestLayout();
}
};
ani.setDuration(2000);
ivScroll.startAnimation(ani);
참고 : http://stackoverflow.com/questions/13881419/android-change-left-margin-using-animation
이렇게 했는데, 애니메이션 안된다.
아래처럼 하면 애니메이션 잘 된다.
int iPagerPageCount = (int)Math.round(Math.ceil((aryGroupIdx.size()*1.0)/(4*1.0)));
int iDeviceWidth = lib_device.getDeviceWidth(photo_send2_activity.this);
int iWidth = iDeviceWidth - lib_common.getPixelValueOfDp(photo_send2_activity.this, 20);
int iLeftMargin = position * (iWidth / iPagerPageCount);
final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)ivScroll.getLayoutParams();
layoutParams.width = iWidth / iPagerPageCount;
ValueAnimator ani = ValueAnimator.ofInt(layoutParams.leftMargin, iLeftMargin);
ani.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override public void onAnimationUpdate(ValueAnimator valueAnimator)
{
layoutParams.leftMargin = (Integer)valueAnimator.getAnimatedValue();
ivScroll.requestLayout();
}
});
ani.setDuration(200);
ani.start();
'Android 초보' 카테고리의 다른 글
안드로이드. 바코드. zxing library (0) | 2015.12.15 |
---|---|
android. 구글맵 (0) | 2015.08.11 |
안드로이드, 배경화면 이미지. 버그 수정 (0) | 2014.12.16 |
adb shell run-as (0) | 2014.12.12 |
안드로이드, 배경화면 이미지 (0) | 2014.07.14 |