设为首页 加入收藏

TOP

Android 实现 IOS相机滑动控件(三)
2017-10-13 10:31:43 】 浏览:4281
Tags:Android 实现 IOS 相机 滑动 控件
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
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇GreenDao2.2升级GreenDao3.0的适.. 下一篇计算机网络和Internet之核心网络

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目