繁体   English   中英

自定义视图中的动画-Android

[英]Animations in custom view - android

对于自定义视图,我在处理动画方面有些困惑。 我现在正在上的是一个像这样的课:

public class ConcreteView extends RelativeLayout {
      //blah blah code
      public ConcreteView(Context context, AttributeSet attrs) {
          //blah blah code
      }
       //blah blah code
}

和这样的xml:

<com.package.ConcreteView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:id="@+id/suggest"
    app:headerText="This is a custom view. Animations yet to be implemented"
    app:headertextColor="#212121"
    app:footerText="Frostbite engine"
    app:footertextColor="#424242"
    app:footertextSize="9"
    app:headerTextFontSize="13"/>

现在,我要寻找的是一种在该类内(以编程方式)实现所有基本动画(如fadeIn,fadeOut,slide In / Out等)的方法,因此我只需要创建ConcreteView实例并访问setAnimation方法。 有任何想法吗?

谢谢,Shantanu

在自定义视图的实现内部,您始终可以使用this运算符访问视图和视图功能。 使用它,您应该能够根据动画更改视图的属性。

所以,这就像

public class ConcreteView extends RelativeLayout {
      //blah blah code
      public ConcreteView(Context context, AttributeSet attrs) {
          //blah blah code
      }
       //blah blah code

      public void blahAnimationFadeOut(){
           this.setAlpha(0.5); // dummy example to access all view functions, assuming you can write your own animations programatically
      }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM