自定义视图中的动画 - android

Animations in custom view - android

当涉及到我的自定义视图时,我在处理动画时有点困惑。 我现在拥有的是 class 这样的:

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"/>

现在我正在寻找的是一种在这个class(以编程方式)以便我只需要创建 ConcreteView 的实例并访问 setAnimation 方法。有什么想法吗?

谢谢, 山塔努

在自定义视图的实现中,您始终可以使用 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
      }
}