字体滚动效果
最近在项目中遇见了字体水平滚动&字体垂直滚动效果,借此与大家分享
<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:singleLine="true"
        android:textSize="30sp"
        android:textColor="@android:color/black"
        android:text="过去对错已不再重要"
        />
public class VerticalSlidingView extends TextSwitcher implements ViewSwitcher.ViewFactory {
    private static final String[] textContents = new String[]{"日照香炉生紫烟","遥看瀑布挂前川","飞流直下三千尺","疑似迎合落九天"};
    public static final int MSG_START_SLIP = 1;
    private Handler mHandler;
    private int num;
    private static final int TIME = 2 * 1000;
    private Handler.Callback mCallBack = new Handler.Callback(){
        @Override
        public boolean handleMessage(Message message) {
            switch (message.what){
                case MSG_START_SLIP:
                    mHandler.sendEmptyMessageDelayed(MSG_START_SLIP , TIME);
                    if(num <= textContents.length -1) {
                        setText(textContents[num++]);
                    }else{
                        num = 0;
                    }
                    break;
            }
            return false;
        }
    };

    public VerticalSlidingView(Context context){
        this(context,null);
    }

    public VerticalSlidingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mHandler = new Handler(mCallBack);
        initView();
    }

    @Override
    public View makeView() {
       TextView textView = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.swith_text_view , null);
        return textView;
    }

    private void initView(){
        setFactory(this);
        /*TextView textView1 = new TextView(getContext());
        ViewGroup.LayoutParams params1 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT , ViewGroup.LayoutParams.WRAP_CONTENT);
        textView1.setTextSize(20);
        textView1.setTextColor(Color.RED);
        textView1.setLayoutParams(params1);
        addView(textView1 , 0);
        TextView textView2 = new TextView(getContext());
        ViewGroup.LayoutParams params2 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT , ViewGroup.LayoutParams.WRAP_CONTENT);
        textView2.setTextSize(30);
        textView2.setTextColor(Color.BLACK);
        textView2.setLayoutParams(params2);
        addView(textView2 , 1);*/
        Animation animationIn = loadAnimation(getContext() , R.anim.slide_in_top);
        Animation animationOut = AnimationUtils.loadAnimation(getContext() , R.anim.slide_out_top);
        setInAnimation(animationIn);
        setOutAnimation(animationOut);
        mHandler.sendEmptyMessageDelayed(MSG_START_SLIP,TIME);
        if(num <= textContents.length - 1) {
            setText(textContents[num++]);
        }else{
            num = 0;
        }
    }
}

LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT , LinearLayout.LayoutParams.WRAP_CONTENT);
        params1.setMargins();