设为首页 加入收藏

TOP

Android 实现 IOS相机滑动控件(四)
2017-10-13 10:31:43 】 浏览:4279
Tags:Android 实现 IOS 相机 滑动 控件
85
} 186 @Override 187 public void onAnimationEnd(Animation animation) { 188 // TODO Auto-generated method stub 189 Log.d(TAG, "onAnimationEnd "); 190 191 for (int i= 0; i < getChildCount(); i++) { 192 getChildAt(i).clearAnimation(); 193 } 194 mRequstLayout = true; 195 requestLayout(); 196 mAnimationRunning = false; 197 if (AnimationRunningCount > 0) { 198 CustomViewL.this.post(new Runnable() { 199 @Override 200 public void run() { 201 // TODO Auto-generated method stub 202 AnimationRunningCount--; 203 mCurrentItem = currentItemCopy; 204 int lastItem = scroolToRight ? currentItemCopy + 1 : currentItemCopy - 1; 205 startTraAnimation(currentItemCopy,lastItem); 206 updateTextColor(); 207 } 208 }); 209 } 210 } 211 @Override 212 public void onAnimationRepeat(Animation animation) { 213 } 214 215 } 216 217 private int AnimitionDurationTime = 300; 218 private int AnimationRunningCount = 0; 219 private boolean mAnimationRunning = false; 220 private boolean mRequstLayout = false; 221 public void startTraAnimation(int item,int last) { 222 Log.d(TAG, "startTraAnimation item = " + item); 223 View v = getChildAt(item); 224 final int width = v.getWidth(); 225 final int childCount = getChildCount(); 226 int traslate = getWidth()/2 - v.getLeft() - width/2; 227 228 int currentItemWidthScale = (int) (width * ItemScale); 229 230 for (int i = 0; i < childCount; i++) { 231 int delta = currentItemWidthScale / 2; 233 Log.d(TAG, " i = " + i + " delta before = " + delta); 234 if (i < item) { 235 delta = -delta; 236 for (int j = i; j < item; j++) { 237 int a; 238 if (i == j) { 239 a = (int)(getChildAt(j).getWidth() * ItemScale / 2); 240 } else { 241 a = (int)(getChildAt(j).getWidth() * ItemScale); 242 } 243 delta = item < last ? delta - a : delta + a; 244 } 245 } else if (i > item){ 246 for (int j = item + 1; j <= i; j++) { 247 int a; 248 if (j == i) { 249 a = (int)(getChildAt(j).getWidth() * ItemScale / 2); 250 } else { 251 a = (int)(getChildAt(j).getWidth() * ItemScale); 252 } 253 delta = item < last ? delta - a : delta + a; 254 } 255 } else { 256 delta = 0; 257 } 258 Log.d(TAG, "delta = " + delta); 259 delta += traslate; 260 TranslateAnimation translateAni = new TranslateAnimation(0, delta, 0, 0); 261 translateAni.setDuration(AnimitionDurationTime); 262 translateAni.setFillAfter(true); 263 if (i == item) translateAni.setAnimationListener(new myAnimationListener()); 264 mAnimationRunning = true; 265 getChildAt(i).startAnimation(translateAni); 266 } 268 } 269 }

 最后说一下布局文件,两边本来是要做一个阴影效果的,为了简便,复习了下PS,就在上面盖了张图片,显得两边有阴影。 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.androidcustomnview.MainActivity" >

    <RelativeLayout
        android:id="@+id/ViewRoot"
        android:gravity="center" 
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <com.example.androidcustomnview.CustomViewL
            android:orientation="horizontal"
            android:bac
首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇GreenDao2.2升级GreenDao3.0的适.. 下一篇计算机网络和Internet之核心网络

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目