1
如何在動畫時更改視圖的座標?例如,如果我在屏幕上從左向右翻譯視圖,我希望視圖將其所有內容都推到右側,以便移動它?Android 2.3:動畫視圖?
public Animation expandHiddenPanel(final View v, final boolean expand) {
panelExpanded = expand;
v.measure(MeasureSpec.makeMeasureSpec(200, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
final int initialWidth = v.getMeasuredWidth();
Log.i("test", "initialWidth = " + initialWidth);
v.getLayoutParams().width = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newWidth;
if (expand) {
newWidth = (int)(initialWidth * interpolatedTime);
Log.i("test", "new Width = " + newWidth);
}
else {
newWidth = (int)(initialWidth * (1 - interpolatedTime));
Log.i("test", "new Width = " + newWidth);
}
v.getLayoutParams().width = newWidth;
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
a.setInterpolator(new AccelerateInterpolator());
a.setDuration(2500);
a.setFillAfter(true);
v.startAnimation(a);
return a;
}
您是否正在嘗試從一項活動轉換爲下一項活動?你能向我們展示一些代碼,而不是真正關注你所問的問題。 – Idistic
基本上我想要做的是有一個面板,默認情況下摺疊從左側滑出(像滑動抽屜),並將相鄰視圖的內容推到右側。 –
你有沒有想過使用ViewSwitcher? – Idistic