展开动画以在两侧工作? (在负轴上)
Expand Animation to work on both sides? (on negative axis)
我在视图上实现了一个 ExpandAnimation,如下所示:
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
LayoutParams lp =
(LayoutParams) view.getLayoutParams();
if(rightAnimation){
lp.width = (int) (mStartWidth + mDeltaWidth *
interpolatedTime);
view.setLayoutParams(lp);
}else{
}
}
有了这个动画,我的视野就会扩大和缩小。
我想做的是将此动画也实现到另一侧(到-x 侧)。但是我有点困惑,因为缩小宽度是行不通的。
(因为不允许使用负宽度或负高度)
有谁知道实现向左 (-x) 或向上 (-y) 展开动画的更好方法吗?
或者镜像视图?
终于实现了左手边展开动画。这是代码:
private class ExpandAnimation extends Animation implements Animation.AnimationListener {
private final int mStartWidth;
private final int mDeltaWidth;
int delta;
public ExpandAnimation(int startWidth, int endWidth) {
mStartWidth = startWidth;
mDeltaWidth = endWidth - startWidth;
RelativeLayout.LayoutParams param = (RelativeLayout.LayoutParams) getLayoutParams();
delta = param.width;
setAnimationListener(this);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
RelativeLayout.LayoutParams param = (RelativeLayout.LayoutParams) getLayoutParams();
delta = param.width;
if(param.width <= 0){
delta = 0;
}
param.width = (int) (mStartWidth + mDeltaWidth *
interpolatedTime);
if(delta != 0){
delta = (int) (mStartWidth + mDeltaWidth *
interpolatedTime) - delta;
}
param.leftMargin -=delta;
setLayoutParams(param);
}
@Override
public boolean willChangeBounds() {
return true;
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
setText(text);
requestLayout();
mExpanded = !mExpanded;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}
由于我不知道的原因,开始时宽度为 -2。所以我用 if 过滤掉它。应用转换方法完成这项工作。
我在视图上实现了一个 ExpandAnimation,如下所示:
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
LayoutParams lp =
(LayoutParams) view.getLayoutParams();
if(rightAnimation){
lp.width = (int) (mStartWidth + mDeltaWidth *
interpolatedTime);
view.setLayoutParams(lp);
}else{
}
}
有了这个动画,我的视野就会扩大和缩小。
我想做的是将此动画也实现到另一侧(到-x 侧)。但是我有点困惑,因为缩小宽度是行不通的。 (因为不允许使用负宽度或负高度)
有谁知道实现向左 (-x) 或向上 (-y) 展开动画的更好方法吗?
或者镜像视图?
终于实现了左手边展开动画。这是代码:
private class ExpandAnimation extends Animation implements Animation.AnimationListener {
private final int mStartWidth;
private final int mDeltaWidth;
int delta;
public ExpandAnimation(int startWidth, int endWidth) {
mStartWidth = startWidth;
mDeltaWidth = endWidth - startWidth;
RelativeLayout.LayoutParams param = (RelativeLayout.LayoutParams) getLayoutParams();
delta = param.width;
setAnimationListener(this);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
RelativeLayout.LayoutParams param = (RelativeLayout.LayoutParams) getLayoutParams();
delta = param.width;
if(param.width <= 0){
delta = 0;
}
param.width = (int) (mStartWidth + mDeltaWidth *
interpolatedTime);
if(delta != 0){
delta = (int) (mStartWidth + mDeltaWidth *
interpolatedTime) - delta;
}
param.leftMargin -=delta;
setLayoutParams(param);
}
@Override
public boolean willChangeBounds() {
return true;
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
setText(text);
requestLayout();
mExpanded = !mExpanded;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}
由于我不知道的原因,开始时宽度为 -2。所以我用 if 过滤掉它。应用转换方法完成这项工作。