v.getLeft() - v.getWidth()/2;
71
72 for (int i = 0; i < getChildCount(); i++) {
73 View v1 = getChildAt(i);
74 if (i == mCurrentItem) {
75 v1.layout(v1.getLeft() + delta, v1.getTop(),
76 v1.getRight() + delta, v1.getBottom());
77 continue;
78 }
79 float mScale = Math.abs(i - mCurrentItem) * ItemScale;
80 int move = (int)(v1.getWidth() * mScale / 2);
81 if (i < mCurrentItem) {
82 for (int j = i + 1; j < mCurrentItem; j++) {
83 View v2 = getChildAt(j);
84 move += (int) (v2.getWidth() * Math.abs(j - mCurrentItem) * ItemScale);
85 }
86 } else {
87 for (int j = i - 1; j > mCurrentItem; j--) {
88 View v2 = getChildAt(j);
89 move += (int)(v2.getWidth() * Math.abs(j - mCurrentItem) * ItemScale);
90 }
91 move = -move;
92 }
93 v1.layout(v1.getLeft() + delta + move, v1.getTop(),
94 v1.getRight() + delta + move, v1.getBottom());
95 }
96 mRequstLayout = false;
97 }
98
99 @Override
100 protected void dispatchDraw(Canvas canvas) {
101 int count = getChildCount();
102 for (int i = 0; i < count; i++) {
103 updateChildItem(canvas,i);
104 }
105 }
106
107 public void updateChildItem(Canvas canvas,int item) {
108 // Log.d(TAG, "updateChildItem");
110 View v = getChildAt(item);
111 float desi = 1- Math.abs(item - mCurrentItem) * ItemScale;
112 ((TextView)v).setScaleX(desi);
113 drawChild(canvas, v, getDrawingTime());
114 updateTextColor();
115 }
118 private void updateTextColor() {
119 for (int i =0 ; i < getChildCount(); i++) {
120 if (i == mCurrentItem) {
121 ((TextView)getChildAt(i)).setTextColor(Color.YELLOW);
122 } else {
123 ((TextView)getChildAt(i)).setTextColor(Color.WHITE);
124 }
125 }
126 }
128 boolean scroolToRight = false;
129
130 public void scrollRight() {
131 if (mRequstLayout) return;
132 if (mCurrentItem > 0) {
133 if (mAnimationRunning) {
134 if (AnimationRunningCount < 1) {
135 currentItemCopy = mCurrentItem - 1;
136 AnimationRunningCount++;
137 scroolToRight = true;
138 }
139 return;
140 }
141 mCurrentItem--;
142 startTraAnimation(mCurrentItem,mCurrentItem + 1);
143 updateTextColor();
144 }
145 }
146
147 private int currentItemCopy;
148 public void scrollLeft() {
149 if (mRequstLayout) return;
150 if (mCurrentItem < getChildCount() - 1) {
151 if (mAnimationRunning) {
152 if (AnimationRunningCount < 1) {
153 currentItemCopy = mCurrentItem + 1;
154 AnimationRunningCount++;
155 scroolToRight = false;
156 }
157 return;
158 }
159 mCurrentItem++;
160 startTraAnimation(mCurrentItem,mCurrentItem-1);
161 updateTextColor();
162 }
163 }
164
165 public void addIndicator(String[] name) {
166 for (int i=0; i< name.length; i++) {
167 TextView mTextView = new TextView(getContext());
168 mTextView.setText(name[i]);
169 mTextView.setTextColor(Color.WHITE);
170 mTextView.setLines(1);
171 LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(
172 LinearLayout.LayoutParams.WRAP_CONTENT,
173 LinearLayout.LayoutParams.WRAP_CONTENT);
174 ll.setMargins(20, 0, 20, 0);
175 addView(mTextView,ll);
176 }
177 }
178
179 class myAnimationListener implements android.view.animation.Animation.AnimationListener {
180
181 @Override
182 public void onAnimationStart(Animation animation) {
183 Log.d(TAG, "onAnimationStart ");
184 mAnimationRunning = true;
1 |