2011-05-16 61 views

回答

0

我通过处理我自己的绘画(onDraw())并使用transfors快速处理切换位置来做这种事情。

0

这将动画从右向左移动TextView。我大部分都是从Android API演示应用程序中复制这些代码。请注意,动画应该经常用XML来描述,而不是用代码来描述,就像这个例子那样。

public class Main extends Activity 
{ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Animation animation = new TranslateAnimation(100, 0, 0, 0); 
    animation.setDuration(2000); 
    animation.setRepeatCount(-1); 

    TextView myTextView = (TextView)findViewById(R.id.my_text_view); 
    myTextView.setAnimation(animation); 
    } 
}

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center"> 
    <TextView 
     android:id="@+id/my_text_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 
</LinearLayout>

建议您查看Android上的动画下列文件。