自己动手写一个动态的三(多)级联动

原创 2017年10月13日 09:13:40

最近项目中用到一个多级联动,可以动态的展示1-3个选择列

这里写图片描述

这张图是预计的实现效果,图片是在其他博客找来的,计划想根据这个样式做一个多级联动

这里写图片描述

布局是这么写的,三个listview,然后上面盖两行分隔线
listview_left
listview_center
listview_right

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <ListView
            android:background="@color/backgroundColor"
            android:layout_weight="1"
            android:scrollbars="none"
            android:divider="@null"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/scrollChangeSelector_listViewOfLeft"></ListView>
        <ListView
            android:background="@color/backgroundColor"
            android:layout_weight="1"
            android:scrollbars="none"
            android:divider="@null"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/scrollChangeSelector_listViewOfCenter"></ListView>
        <ListView
            android:background="@color/backgroundColor"
            android:layout_weight="1"
            android:scrollbars="none"
            android:divider="@null"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/scrollChangeSelector_listViewOfRight"></ListView>
    </LinearLayout>
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/dotted_line_color"/>
            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/queryDialogChildHeight"/>
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/dotted_line_color"/>
        </LinearLayout>
    </FrameLayout>
</FrameLayout>

然后自定义一个FrameLayout,引入这个布局

public class ScrollChangeSelector extends FrameLayout  {

     private Context context;

     private ListView selectorListView_left;

     private ListView selectorListView_center;

     private ListView selectorListView_right;

     public ScrollChangeSelector(Context context) {
            super(context);
            this.context = context;
            init();
        }


      public ScrollChangeSelector(Context context, AttributeSet attrs) {
            super(context, attrs);
            this.context = context;
            init();
      }

      private void init() {
            View.inflate(context,R.layout.view_scroll_change_selector,this);
            selectorListView_left = findViewById(R.id.scrollChangeSelector_listViewOfLeft);
             selectorListView_center = findViewById(R.id.scrollChangeSelector_listViewOfCenter);
            selectorListView_right = findViewById(R.id.scrollChangeSelector_listViewOfRight);
    }

    ...省略...
}

核心看一下我是怎么实现item翻转的

    private ValueAnimator itemRotationAnimator;

    private int animatorDuration = 200;//动画时长


    private final void itemRotationAnimator(final TextView itemTv,final int start,final int end){
        itemRotationAnimator = new ValueAnimator().ofInt(start,end);
        itemRotationAnimator.setDuration(animatorDuration);
        itemRotationAnimator.setRepeatCount(0);
        itemRotationAnimator.setInterpolator(new LinearInterpolator());
        itemRotationAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int value = (int) animation.getAnimatedValue();
                itemTv.setRotationX(value);
                if(value == end){
                    itemTv.clearAnimation();
                }
            }
        });
        itemRotationAnimator.start();
    }

贴出完整的代码:

package com.zzyd.view;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.zzyd.hrm.R;

import java.util.List;

/**
 * Created by Administrator on 2017/10/10 0010.
 *
 * 滑动选择器
 *
 * http://blog.csdn.net/u013003312/article/details/52426965
 * 按照上面的博客的样子做一个
 *
 * 最大条数:3个
 *
 * 完美造轮子~
 *
 */

public class ScrollChangeSelector extends FrameLayout  {

    /**
     * 声明三个数据源
     * 三个选择器
     * 三个适配器
     */
    private List<String> dataOfSelector_left;
    private List<String> dataOfSelector_center;
    private List<String> dataOfSelector_right;

    private Context context;

    private ListView selectorListView_left;

    private ListView selectorListView_center;

    private ListView selectorListView_right;

    private SelectorAdapter selectorAdapter_left;
    private SelectorAdapter selectorAdapter_center;
    private SelectorAdapter selectorAdapter_right;

    private int numberOfColumn;//当前选择器的条目数量,最大3个

    private final int scrollOverVisibleNum = 3;//选择器滚动到边界时显示的item数量,默认3

    private int itemTvSize = 13;//文字大小

    private ScrollChangeSelectorListener selectorListener;

    public ScrollChangeSelector(Context context) {
        super(context);
        this.context = context;
        init();
    }


    public ScrollChangeSelector(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    private void init() {
        View.inflate(context,R.layout.view_scroll_change_selector,this);
        selectorListView_left = findViewById(R.id.scrollChangeSelector_listViewOfLeft);
        selectorListView_center = findViewById(R.id.scrollChangeSelector_listViewOfCenter);
        selectorListView_right = findViewById(R.id.scrollChangeSelector_listViewOfRight);
//        setData(0,null,null);
//        setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,80*7));

    }

    public ScrollChangeSelectorListener getSelectorListener() {
        return selectorListener;
    }

    public void setSelectorListener(ScrollChangeSelectorListener selectorListener) {
        this.selectorListener = selectorListener;
    }

    public void setData(int numberOfColumn, List<String>... data){
        this.numberOfColumn = numberOfColumn;
//        results = new String[numberOfColumn];
        clearStatus();
        switch (numberOfColumn){
            case 1:
                initLeft(data);
                selectorListView_center.setVisibility(GONE);
                selectorListView_right.setVisibility(GONE);
                break;
            case 2:
                initLeft(data);
                initCenter(data);
                selectorListView_right.setVisibility(GONE);
                break;
            case 3:
                initLeft(data);
                initCenter(data);
                initRight(data);
                break;
        }
    }

    public void clear(){
        dataOfSelector_left = null;
        dataOfSelector_center = null;
        dataOfSelector_right = null;
        selectorAdapter_left = null;
        selectorAdapter_center = null;
        selectorAdapter_right = null;
        selectorListView_left.setSelection(0);
        selectorListView_center.setSelection(0);
        selectorListView_right.setSelection(0);
//        results = null;
        arg0 = "";
        arg1 = "";
        arg2 = "";
    }

    private void initLeft(List<String>... data){
        this.dataOfSelector_left = data[0];
        if(selectorAdapter_left == null){
            selectorAdapter_left = new SelectorAdapter(data[0],1);
            selectorListView_left.setAdapter(selectorAdapter_left);
            selectorListView_left.setOnScrollListener(onScrollListener_left);
            selectorListView_left.setVisibility(VISIBLE);
            selectorListView_left.smoothScrollToPosition(0);
//            selectorAdapter_left.notifyDataSetChanged();
        }else{
            selectorAdapter_left.setData(data[0]);
        }
//        arg0 = selectorAdapter_left.getCenterItemInfo();
//        Log.e("initLeft","arg0:"+arg0);
//        if(selectorListener != null) {
//            selectorListener.onSelector(arg0,arg1,arg2);
//        }
        this.dataOfSelector_left = selectorAdapter_left.getDataForSelector();
//        selectorListView_left.setOnItemClickListener(onItemClick_left);
//        selectorAdapter_left.setCallBack(callBack);
    }

    private void initCenter(List<String>... data){
        this.dataOfSelector_center = data[1];
        if(selectorAdapter_center == null){
            selectorAdapter_center = new SelectorAdapter(data[1],2);
            selectorListView_center.setAdapter(selectorAdapter_center);
            selectorListView_center.setOnScrollListener(onScrollListener_center);
            selectorListView_center.setVisibility(VISIBLE);
            selectorListView_center.smoothScrollToPosition(0);
//            selectorAdapter_center.notifyDataSetChanged();
        }else{
            selectorAdapter_center.setData(data[1]);
//            selectorListView_center.setSelection(0);
        }
//        arg1 = selectorAdapter_center.getCenterItemInfo();
//        Log.e("initLeft","arg1:"+arg1);
//        if(selectorListener != null) {
//            selectorListener.onSelector(arg0,arg1,arg2);
//        }
        this.dataOfSelector_center = selectorAdapter_center.getDataForSelector();
    }

    private void initRight(List<String>... data){
        this.dataOfSelector_right = data[2];
        if(selectorAdapter_right == null){
            selectorAdapter_right = new SelectorAdapter(data[2],3);
            selectorListView_right.setAdapter(selectorAdapter_right);
            selectorListView_right.setOnScrollListener(onScrollListener_right);
            selectorListView_right.setVisibility(VISIBLE);
            selectorListView_right.smoothScrollToPosition(0);
//            selectorAdapter_right.notifyDataSetChanged();
        }else{
            selectorAdapter_right.setData(data[2]);
//            selectorListView_right.setSelection(0);
        }
//        arg2 = selectorAdapter_right.getCenterItemInfo();
//        Log.e("initLeft","arg2:"+arg2);
//        if(selectorListener != null) {
//            selectorListener.onSelector(arg0,arg1,arg2);
//        }
        this.dataOfSelector_right = selectorAdapter_right.getDataForSelector();
    }

    private void clearStatus(){
        selectorListView_left.setVisibility(VISIBLE);
        selectorListView_center.setVisibility(VISIBLE);
        selectorListView_right.setVisibility(VISIBLE);
    }

    public int getNumberOfColumn() {
        return numberOfColumn;
    }

    SelectorAdapterCallBack callBack = new SelectorAdapterCallBack() {
        @Override
        public void onItemClick(int position) {
            try {
                String value = dataOfSelector_left.get(position);
                selectorListView_left.smoothScrollToPosition(position - 2);
            }catch (IndexOutOfBoundsException i){

            }catch (NullPointerException n){}
        }
    };

    public String getArg0() {
        return arg0;
    }

    public String getArg1() {
        return arg1;
    }

    public String getArg2() {
        return arg2;
    }

    /**
     * 这个handler的作用是让listView延迟归位
     */
    private Handler handler = new Handler(){
        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);
            switch (msg.what){
                case 0x1111:
                    specification(selectorListView_left,msg.getData().getInt("0x1111"));
                    break;
                case 0x2222:
                    specification(selectorListView_center,msg.getData().getInt("0x2222"));
                    break;
                case 0x3333:
                    specification(selectorListView_right,msg.getData().getInt("0x3333"));
                    break;
                case 0x0099:
                    onTouchSelect = 0;
                    break;
            }
        }
    };

    private int viewWidth;

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        viewWidth = MeasureSpec.getSize(widthMeasureSpec);
//        Log.e("onMeasure","viewWidth:"+viewWidth);
    }

    /**
     * 当手指触碰屏幕时,判断触摸的是哪个listView
     */
    private int onTouchSelect = -1;

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                int downX = (int) ev.getX();
//                Log.e("onMeasure","downX__:"+downX);
                switch (getNumberOfColumn()){
                    case 1:
                        onTouchSelect = 1;
                        break;
                    case 2:
                        if(downX > 0 && downX < (viewWidth / 2)){
                            onTouchSelect = 1;
                        }
                        if(downX > (viewWidth / 2) && downX < viewWidth){
                            onTouchSelect = 2;
                        }
                        break;
                    case 3:
                        if(downX > 0 && downX < (viewWidth / 3) * 1){
                            onTouchSelect = 1;
                        }
                        if(downX > (viewWidth / 3) * 1 && downX < (viewWidth / 3) * 2){
                            onTouchSelect = 2;
                        }
                        if(downX > (viewWidth / 3) * 2 && downX < viewWidth){
                            onTouchSelect = 3;
                        }
                        break;
                }
                break;
            case MotionEvent.ACTION_UP:
//                onTouchSelect = 0;
                postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        延迟归位
                        Message msg = new Message();
                        msg.what = 0x0099;
                        handler.sendMessage(msg);
                    }
                },150);
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

    /**
     * firstVisibleItem:当前能看到的第一个item id
     * visibleItemCount:当前能看到的item 总数
     * totalItemCount:absListView中Item的总数
     */

//    private String[] results;

    private String arg0,arg1,arg2 = "";

    AbsListView.OnScrollListener onScrollListener_left = new AbsListView.OnScrollListener() {

        int firstVisibleItem;
        int visibleItemCount;
        int totalItemCount;
        int centerItem;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE){
                postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Message msg = new Message();
                        msg.what = 0x1111;
                        Bundle bundle = new Bundle();
                        bundle.putInt("0x1111",firstVisibleItem);
                        msg.setData(bundle);
                        handler.sendMessage(msg);
                    }
                },100);
            }
        }

        int oldFirstVisibleItem;

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if(onTouchSelect != 1){
                return;
            }
            this.firstVisibleItem = firstVisibleItem;
            this.visibleItemCount = visibleItemCount;
            this.totalItemCount = totalItemCount;
            if(oldFirstVisibleItem != firstVisibleItem){
                this.oldFirstVisibleItem =  firstVisibleItem ;
                this.centerItem = firstVisibleItem + scrollOverVisibleNum;//centerItem就是当前选中的
                try {
                    getSelectorAdapter_left().setCenterItem(centerItem);
                    getSelectorAdapter_left().setFirstVisibleItem(firstVisibleItem);
                    getSelectorAdapter_left().setVisibleItemCount(visibleItemCount);
                    getSelectorAdapter_left().notifyDataSetChanged();
                    arg0 = ((TextView)getSelectorAdapter_left().getView(centerItem,null,null)).getText().toString();
//                Log.e("onScroll","info:"+info);
                    if(selectorListener != null) {
                        selectorListener.onChangeSelector(arg0,arg1,arg2);
                    }
                }catch (IndexOutOfBoundsException e){

                }catch (NullPointerException n){}
            }
        }
    };

    AbsListView.OnScrollListener onScrollListener_center = new AbsListView.OnScrollListener() {

        int firstVisibleItem;
        int visibleItemCount;
        int totalItemCount;
        int centerItem;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE){
                postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Message msg = new Message();
                        msg.what = 0x2222;
                        Bundle bundle = new Bundle();
                        bundle.putInt("0x2222",firstVisibleItem);
                        msg.setData(bundle);
                        handler.sendMessage(msg);
                    }
                },100);
            }
        }

        int oldFirstVisibleItem;

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if(onTouchSelect != 2){
                return;
            }
            this.firstVisibleItem = firstVisibleItem;
            this.visibleItemCount = visibleItemCount;
            this.totalItemCount = totalItemCount;
            if(oldFirstVisibleItem != firstVisibleItem){
                this.oldFirstVisibleItem = firstVisibleItem;
                this.centerItem = firstVisibleItem + scrollOverVisibleNum;//centerItem就是当前选中的
                try {
                    getSelectorAdapter_center().setCenterItem(centerItem);
                    getSelectorAdapter_center().setFirstVisibleItem(firstVisibleItem);
                    getSelectorAdapter_center().setVisibleItemCount(visibleItemCount);
                    getSelectorAdapter_center().notifyDataSetChanged();
                    arg1 = ((TextView)getSelectorAdapter_center().getView(centerItem,null,null)).getText().toString();
//                Log.e("onScroll","info:"+info);
                    if(selectorListener != null) {
                        selectorListener.onChangeSelector(arg0,arg1,arg2);
                    }
                }catch (IndexOutOfBoundsException e){

                }catch (NullPointerException n){}
            }
        }
    };

    AbsListView.OnScrollListener onScrollListener_right = new AbsListView.OnScrollListener() {

        int firstVisibleItem;
        int visibleItemCount;
        int totalItemCount;
        int centerItem;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE){
                postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Message msg = new Message();
                        msg.what = 0x3333;
                        Bundle bundle = new Bundle();
                        bundle.putInt("0x3333",firstVisibleItem);
                        msg.setData(bundle);
                        handler.sendMessage(msg);
                    }
                },100);
            }
        }

        int oldFirstVisibleItem;

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if(onTouchSelect != 3){
                return;
            }
            this.firstVisibleItem = firstVisibleItem;
            this.visibleItemCount = visibleItemCount;
            this.totalItemCount = totalItemCount;
            if(oldFirstVisibleItem != firstVisibleItem){
                this.oldFirstVisibleItem = firstVisibleItem;
                this.centerItem = firstVisibleItem + scrollOverVisibleNum;//centerItem就是当前选中的
                try {
                    getSelectorAdapter_right().setCenterItem(centerItem);
                    getSelectorAdapter_right().setFirstVisibleItem(firstVisibleItem);
                    getSelectorAdapter_right().setVisibleItemCount(visibleItemCount);
                    getSelectorAdapter_right().notifyDataSetChanged();
                    arg2 = ((TextView)getSelectorAdapter_right().getView(centerItem,null,null)).getText().toString();
//                Log.e("onScroll","info:"+info);
                    if(selectorListener != null) {
                        selectorListener.onChangeSelector(arg0,arg1,arg2);
                    }
                }catch (IndexOutOfBoundsException e){

                }catch (NullPointerException n){}
            }
        }
    };

    /**
     * 规范这些item
     */
    public void specification(ListView listView,int position){
//        listView.smoothScrollBy();
//        listView.smoothScrollToPosition(position);
        listView.setSelection(position);
    }

    /**
     * item翻转动画
     */
    private ValueAnimator itemRotationAnimator;

    private int animatorDuration = 200;//动画时长


    private final void itemRotationAnimator(final TextView itemTv,final int start,final int end){
        itemRotationAnimator = new ValueAnimator().ofInt(start,end);
        itemRotationAnimator.setDuration(animatorDuration);
        itemRotationAnimator.setRepeatCount(0);
        itemRotationAnimator.setInterpolator(new LinearInterpolator());
        itemRotationAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int value = (int) animation.getAnimatedValue();
                itemTv.setRotationX(value);
                if(value == end){
                    itemTv.clearAnimation();
                }
            }
        });
        itemRotationAnimator.start();
    }


    public List<String> getDataOfSelector_left() {
        return dataOfSelector_left;
    }

    public List<String> getDataOfSelector_center() {
        return dataOfSelector_center;
    }

    public List<String> getDataOfSelector_right() {
        return dataOfSelector_right;
    }

    public ListView getSelectorListView_left() {
        return selectorListView_left;
    }

    public ListView getSelectorListView_center() {
        return selectorListView_center;
    }

    public ListView getSelectorListView_right() {
        return selectorListView_right;
    }

    public SelectorAdapter getSelectorAdapter_left() {
        if(selectorAdapter_left == null){
            return new SelectorAdapter();
        }
        return selectorAdapter_left;
    }

    public SelectorAdapter getSelectorAdapter_center() {
        return selectorAdapter_center;
    }

    public SelectorAdapter getSelectorAdapter_right() {
        return selectorAdapter_right;
    }

    public int getScrollOverVisibleNum() {
        return scrollOverVisibleNum;
    }

    class SelectorAdapter extends BaseAdapter{

        private List<String> dataForSelector;

        private int itemViewHeight = 80;

        private int centerItem = 3;

        private int firstVisibleItem;
        private int visibleItemCount;

        private SelectorAdapterCallBack callBack;

        private String centerItemInfo = "";

        private int type = 0;

        public SelectorAdapter(){}

        public SelectorAdapter(List<String> dataForSelector,int type){
            if(dataForSelector == null){
                return;
            }
            this.type = type;
            this.dataForSelector = dataForSelector;
            /**
             * 设置数据后增加一点操作,目的增加一个过度滚动
             */
            for(int i = 0 ; i < scrollOverVisibleNum ; i ++){
                this.dataForSelector.add(i,"");
            }
            for(int i = 0 ; i < scrollOverVisibleNum ; i ++){
                this.dataForSelector.add("");
            }
        }

        private List<String> oldData;

        public void setData(List<String> dataForSelector){
            if(dataForSelector == null){
                return;
            }
            if(this.dataForSelector != dataForSelector){
                this.dataForSelector = dataForSelector;
                /**
                 * 设置数据后增加一点操作,目的增加一个过度滚动
                 */
                for(int i = 0 ; i < scrollOverVisibleNum ; i ++){
                    this.dataForSelector.add(i,"");
                }
                for(int i = 0 ; i < scrollOverVisibleNum ; i ++){
                    this.dataForSelector.add("");
                }
                notifyDataSetChanged();
            }
        }

        public String getCenterItemInfo() {
            return centerItemInfo;
        }

        public SelectorAdapterCallBack getCallBack() {
            return callBack;
        }

        public void setCallBack(SelectorAdapterCallBack callBack) {
            this.callBack = callBack;
        }

        public List<String> getDataForSelector() {
            return dataForSelector;
        }

        public int getItemViewHeight() {
            return itemViewHeight;
        }

        public int getCenterItem() {
            return centerItem;
        }

        public void setCenterItem(int centerItem) {
            this.centerItem = centerItem;
        }

        public void setItemViewHeight(int itemViewHeight) {
            this.itemViewHeight = itemViewHeight;
        }

        public int getFirstVisibleItem() {
            return firstVisibleItem;
        }

        public void setFirstVisibleItem(int firstVisibleItem) {
            this.firstVisibleItem = firstVisibleItem;
        }

        public int getVisibleItemCount() {
            return visibleItemCount;
        }

        public void setVisibleItemCount(int visibleItemCount) {
            this.visibleItemCount = visibleItemCount;
        }

        @Override
        public int getCount() {
            return dataForSelector.size();
        }

        @Override
        public Object getItem(int position) {
            return dataForSelector.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            TextView itemTv = null;
            try {
                itemTv = new TextView(context);
                ListView.LayoutParams itemTvParams =
                        new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,itemViewHeight);
                itemTv.setGravity(Gravity.CENTER);
                itemTv.setTextSize(itemTvSize);
                itemTv.setBackgroundColor(Color.WHITE);
                itemTv.setText(dataForSelector.get(position));
//                this.centerItemInfo = dataForSelector.get(position);
                itemTv.setLayoutParams(itemTvParams);
                if(centerItem == position){
//                    Log.e("initLeft","arg0:"+dataForSelector.get(position));
                    if(type == 1){
                        arg0 = dataForSelector.get(position);
                    }
                    if(type == 2){
                        arg1 = dataForSelector.get(position);
                    }
                    if(type == 3){
                        arg2 = dataForSelector.get(position);
                    }
                    itemTv.setTextColor(ContextCompat.getColor(context,R.color.themeColor));
                }else{
                    itemTv.setTextColor(ContextCompat.getColor(context,R.color.textColor_low));
                }
                if(position == firstVisibleItem+ 2){
                    itemRotationAnimator(itemTv,90 - 25 - 25 ,90 - 25 - 25 -25);
                }
                if(position == firstVisibleItem + 1){
                    itemRotationAnimator(itemTv,90 - 25,90 - 25 - 25);
                }
                if(position == firstVisibleItem){
                    itemRotationAnimator(itemTv,90,90 - 25);
                }
                if(position == centerItem + 1){
                    itemRotationAnimator(itemTv,0,0 - 25);
                }
                if(position == centerItem + 2){
                    itemRotationAnimator(itemTv,0 - 25,0 - 25 - 25 );
                }
                if(position == centerItem + 3){
                    itemRotationAnimator(itemTv,0 - 25 - 25 ,0 - 25 - 25 -25);
                }
//                itemTv.setOnClickListener(new OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if(callBack != null){
//                            callBack.onItemClick(position);
//                        }
//                    }
//                });
            }catch (StackOverflowError e){}
            return itemTv;
        }

    }

    public interface SelectorAdapterCallBack{

        public void onItemClick(int position);

    }


    /**
     * 回调监听
     */
    public interface ScrollChangeSelectorListener{

        public void onChangeSelector(String arg0,String arg1,String arg2);

        public void onSelector(String arg0,String arg1,String arg2);

    }
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Spring MVC 3.2 技术预览(三):动手写一个异步Controller方法

原文地址:http://blog.springsource.org/2012/05/10/spring-mvc-3-2-preview-making-a-controller-method-async...

自己动手写Web容器之TomJetty之六:动态页面引入

传送门 ☞ Android兵器谱 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229 传送门 ☞ 系统架构设计 ☞ 转载请注明 ☞ http...

自己动手写数据结构:Stack类模板的动态数组实现

#ifndef MYSTACK_H #define MYSTACK_H #include template class MyStack { public: MyStack():val(ne...

Angular 2 + 折腾记 :(8) 动手写一个不怎么靠谱的上传组件

前言上传功能在任何一个网站中的地位都是举足轻重的,这篇文章主要扯下如何实现一个上传组件
  • bomess
  • bomess
  • 2017-04-05 14:39
  • 2486

《自己动手写一个操作系统》个人实践1

根据《自己动手写操作系统》一书个人的实践,用ubuntu14制作 boot.bin 开始步骤: 注意: 如果在安装ubuntu14系统过程中没有设置root密码,安装完后 在ubuntu14中通过命令...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)