公告由下到上循环滚动的自定义view

1.文字进入的动画


android:duration="1000"
android:fromYDelta="100%"
android:toYDelta="0" />
android:duration="1000"
android:fromAlpha="0.0"
android:toAlpha="1.0" />

2.文字退出的动画



android:duration="1000"
android:fromYDelta="0"
android:toYDelta="-100%" />
android:duration="1000"
android:fromAlpha="1.0"
android:toAlpha="0.0" />

3.自定义view

public class NoticeView extends ViewFlipper {

private Context mContext;
private int fontSize;
private int textColor;

public NoticeView(Context context) {
    super(context);
    mContext = context;
    initView();
}

public NoticeView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.NoticeView);
    //获取字体大小,默认大小是12sp
    fontSize = (int) ta.getDimension(R.styleable.NoticeView_text_font, 12);
    Log.i("fontSize","fontSize:"+fontSize);
    //获取文字颜色,默认颜色是BLUE
    textColor = ta.getColor(R.styleable.NoticeView_text_color, Color.GRAY);
    ta.recycle();
    initView();
}

private void initView() {
    setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.notice_slide_in_bottom));
    setOutAnimation(AnimationUtils.loadAnimation(mContext, R.anim.notice_slide_out_top));
}
public void showNoticeMessages(List messages, NoticeClickListener listener) {
    if (messages == null || messages.size() == 0) {
        return;
    }

    removeAllViews();
    startFlipping();
    setAutoStart(true);
    for (int i = 0;i 

}

你可能感兴趣的:(公告由下到上循环滚动的自定义view)