Androidニュース掲示板切り替え効果(上下スクロール&左右スクロール)

12950 ワード

今日、宝を洗う1つの効果を見て、前にしたAppの中でしたことがなくて、実現しました.オリジナルのコントロールTextSwitcherを使用し,簡単なパッケージ処理を行った.
くだらないことは言わないで、コードを出してください.

package com.panghu.view;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;


import com.panghu.R;


/**
 *
 *       
 *
 * Wetchat : ljphhj
 * Github : https://github.com/xiaoyaomeng
 * Autor : lijiangping
 */
public class CustomTextSwitcher extends TextSwitcher implements ViewSwitcher.ViewFactory {

    private Context mContext;
    private String[] mData;
    private final long DEFAULT_TIME_SWITCH_INTERVAL = 1000;//1s
    private long mTimeInterval = DEFAULT_TIME_SWITCH_INTERVAL;
    private int mCurrentIndex = 0;

    public CustomTextSwitcher(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        setFactory(this);
    }

    public CustomTextSwitcher setInAnimation(int animationResId){
        Animation animation = AnimationUtils.loadAnimation(this.mContext, animationResId);
        setInAnimation(animation);
        return this;
    }

    public CustomTextSwitcher setOutAnimation(int animationResId){
        Animation animation = AnimationUtils.loadAnimation(this.mContext, animationResId);
        setOutAnimation(animation);
        return this;
    }

    /**
     *   /      
     * @param data
     * @return
     */
    public CustomTextSwitcher bindData(String[] data){
        this.mData = data;
        return this;
    }

    public void startSwitch(long timeInterval){
        this.mTimeInterval = timeInterval;
        if (mData != null && mData.length != 0) {
            mSwitchHandler.sendEmptyMessage(0);
        }else{
            throw new RuntimeException("data is empty");
        }
    }

    /**
     *       TextView  TextSwitcher  
     * @return
     */
    @Override
    public View makeView() {
        TextView view = new TextView(this.mContext);
        return view;
    }

    private Handler mSwitchHandler = new Handler(){
        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);
            int index = mCurrentIndex % mData.length;
            mCurrentIndex++;
            setText(mData[index]);
            sendEmptyMessageDelayed(0, mTimeInterval);
        }
    };

}


Demoダウンロードアドレス:https://github.com/xiaoyaomeng/CustomTextSwitcher