2011-06-15 77 views
0

我有一个观点的布局是这样的:安卓:放大/缩小查看随着时间的推移

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:background="@color/light_gray" 
    android:padding="5dip"> 

    <View android:id="@+id/fixedSpace" android:layout_width="fill_parent" 
     android:layout_height="50dip" android:background="@color/aqua" 
     android:layout_alignParentBottom="true" android:clickable="true" 
     android:onClick="onClickStartAnimation" /> 

    <View android:id="@+id/dynamicSpace" android:layout_width="fill_parent" 
     android:layout_height="200dip" android:background="@color/lime" 
     android:layout_above="@id/fixedSpace" /> 


    <View android:id="@+id/remainingSpace" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:background="@color/pink" 
     android:layout_alignParentTop="true" android:layout_above="@id/dynamicSpace" /> 


</RelativeLayout> 

我想实现基本上是一个放大/缩小的dynamicSpace行为在时间。与动画我可以产生以下:

t = 1时:

t=1

t = 2时:

t=2

T = 3:

t=3

但是,这并没有真正调整我的意见,特别是dynamicSpaceremainingSpace。它只是动画dynamicSpace移动的视图。但“容器”视图从一开始就占用了空间。

正确的是石灰色dynamicSpace以0px开头,粉红色的remainingSpace接管,因此中间没有灰色空间。

回答

0

Scale the View

既然你说你正在做它随着时间的推移,这听起来像一个LinearInterpolator是最好的。

+0

我确实使用过动画。但是,这并不能解决真正增长或缩小实际观点的问题。它只是为它制作动画。将在我的问题中提供更多信息。 – znq 2011-06-16 09:35:00

+0

为什么你不能在动画之后重新调整视图的大小(因为你知道你有多大的动画效果)? – hwrdprkns 2011-06-16 12:41:20

+0

这不起作用,因为这是一个调整大小的步骤。但是我真正想要的是随着时间的推移调整大小。动画并没有真正调整任何东西(他们看起来像是这样)。 – znq 2011-06-16 12:44:09

0

编辑: 我试着用AsyncTask线替换下面的线程,它更光滑。我认为关键是我一直的线程在后台运行,只是使用它时,我想调整的东西,从而减少开销


创建自定义AnimationListener并把代码在onAnimationRepeat方法调整视图。

然后做一个虚拟动画,并将动画重复设置为无限。当视图已经达成了动画的最终大小,设置重复计数为零(再次onAnimationRepeat):

class ResizeAnimationListener implements AnimationListener{ 

int finalHeight; // max Height 
int resizeAmount; // amount to resize each time 
View view; // view to resize 

public ResizeAnimationListener(int finalHeight; View view, int resizeAmount) { 
    super(); 
    finalHeight; = finalHeight; 
    this.resizeAmount = resizeAmount; 
    this.view = view; 

} 

@Override 
public void onAnimationEnd(Animation animation) { 

} 

@Override 
public void onAnimationRepeat(Animation animation) { 

    int newHeight; 
    int currentHeight; 

    current = view.getMeasuredHeight(); 

    newHeight= currentHeight+ resizeAmount; 
    if(newHeight> finalHeight){ 
     // check if reached final height 

     // set new height to the final height 
     newHeight = finalHeight; 
     // set repeat count to zero so we don't have any more repeats 
     anim.setRepeatCount(0); 

    } 

    // set new height 
    LayoutParams params = view.getLayoutParams();           
    params.height = newHeight; 
    v.setLayoutParams(params);          

} 

@Override 
public void onAnimationStart(Animation animation) { 

} 

}; 

class DummyAnimation extends Animation{} 


float frameRate = 1000/30;        
DummyAnimation anim = new DummyAnimation(); 
anim.setDuration((long)frameRate);       
anim.setRepeatCount(Animation.INFINITE); 
ResizeAnimationListener animListener = new ResizeAnimationListener(((View)view.getParent()).getHeight(), view, 25); 
anim.setAnimationListener(animListener); 

view.startAnimation(anim); 

我做了我自己的应用程序这项工作。然而,我调整视图的视图(当我调整视图的大小时,因此在屏幕上移动)似乎失灵了。可能与反复调整大小有关,而不是其他任何事情,但只是一个警告。也许别人知道为什么?

相关问题