Android AlphaAnimation适用于StatesListDrawable的不同状态

时间:2014-07-11 15:53:00

标签: android android-layout android-animation android-button

我试图完成类似于我的按钮的淡出效果。

http://www.polymer-project.org/components/paper-calculator/demo.html

但我无法在我的淡入淡出动画中看到用我的代码完成此操作的位置。

我不能用XML定义它,因为我需要从SQLite数据库以编程方式下注颜色。

这是我的CustomStatesList:

public class CustomStateList extends StateListDrawable {

private int backgroundColor, highlightColor, selectedColor;
private int stateFocused = android.R.attr.state_focused;
private int statePressed = android.R.attr.state_pressed;
private int stateSelected = android.R.attr.state_selected;
private ShapeDrawable mCircleShape, mSquareShape;
private LayerDrawable mLayer;


public CustomStateList(Context mContext, int backgroundColor, int highlightColor, int selectedColor) {
    this.backgroundColor = backgroundColor;
    this.highlightColor = highlightColor;
    this.selectedColor = selectedColor;

    mCircleShape = new ShapeDrawable();
    mCircleShape.setShape(new OvalShape());
    mCircleShape.getPaint().setColor(highlightColor);

    mSquareShape = new ShapeDrawable();
    mSquareShape.setShape(new RectShape());
    mSquareShape.getPaint().setColor(backgroundColor);

    Drawable[] layers = new Drawable[] {mSquareShape, mCircleShape};
    mLayer = new LayerDrawable(layers);

    this.addState(new int[] {stateFocused }, mLayer);
    this.addState(new int[] {statePressed }, mLayer);
    this.addState(new int[] {stateSelected }, new ColorDrawable(selectedColor));
    this.addState(new int[]{}, mSquareShape);
}

public int getBackgroundColor() {
    return backgroundColor;
}

public void setBackgroundColor(int backgroundColor) {
    this.backgroundColor = backgroundColor;
}

public int getHighlightColor() {
    return highlightColor;
}

public void setHighlightColor(int highlightColor) {
    this.highlightColor = highlightColor;
}

}

我想要做的就是制作这个动画:

final Animation out = new AlphaAnimation(1.0f, 0.0f);

每当淡出而不仅仅是瞬间消失时应用于StatesListDrawable。但我不知道在哪里申请它!有什么想法吗?

谢谢!

0 个答案:

没有答案