├── .classpath ├── .gitattributes ├── .gitignore ├── .project ├── 556546546.gif ├── AndroidManifest.xml ├── README.md ├── ic_launcher-web.png ├── libs └── android-support-v4.jar ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ ├── ic_launcher.png │ ├── photo1.jpg │ ├── photo2.jpg │ ├── photo3.jpg │ ├── photo4.jpg │ ├── photo5.jpg │ ├── photo6.jpg │ └── photo7.jpg ├── drawable-xxhdpi │ └── ic_launcher.png ├── layout │ └── activity_gallery.xml ├── menu │ └── gallery.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml ├── values-w820dp │ └── dimens.xml └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── src └── com └── example └── gallery ├── GalleryActivity.java └── GalleryView.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Gallery 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /556546546.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/556546546.gif -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gallery 2 | a Gallery demo like the souhu app 3 | 4 | 一个搜狐视频 画廊效果的demo 5 | ![](http://jcodecraeer.com/uploads/20150415/1429064186236674.gif) 6 | 7 | 相关文章: [ http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0414/2723.html]( http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0414/2723.html) 8 | -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/ic_launcher-web.png -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/libs/android-support-v4.jar -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-21 15 | android.library.reference.1=../appcompat_v7 16 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/photo1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xhdpi/photo1.jpg -------------------------------------------------------------------------------- /res/drawable-xhdpi/photo2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xhdpi/photo2.jpg -------------------------------------------------------------------------------- /res/drawable-xhdpi/photo3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xhdpi/photo3.jpg -------------------------------------------------------------------------------- /res/drawable-xhdpi/photo4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xhdpi/photo4.jpg -------------------------------------------------------------------------------- /res/drawable-xhdpi/photo5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xhdpi/photo5.jpg -------------------------------------------------------------------------------- /res/drawable-xhdpi/photo6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xhdpi/photo6.jpg -------------------------------------------------------------------------------- /res/drawable-xhdpi/photo7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xhdpi/photo7.jpg -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianghejie/Gallery/44b33b37418d167cbd6ac7dbe677c88c4dfbedcc/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/layout/activity_gallery.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /res/menu/gallery.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 64dp 9 | 10 | 11 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Gallery 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/com/example/gallery/GalleryActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.gallery; 2 | 3 | import android.support.v7.app.ActionBarActivity; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ObjectAnimator; 6 | import android.annotation.SuppressLint; 7 | import android.content.Context; 8 | import android.content.res.TypedArray; 9 | import android.os.Bundle; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.AdapterView; 15 | import android.widget.BaseAdapter; 16 | import android.widget.Gallery; 17 | import android.widget.ImageView; 18 | 19 | public class GalleryActivity extends ActionBarActivity { 20 | private int[] myImageIds = {R.drawable.photo1, 21 | R.drawable.photo2, 22 | R.drawable.photo3, 23 | R.drawable.photo4, 24 | R.drawable.photo5, 25 | R.drawable.photo6,R.drawable.photo7}; 26 | int lastSelectedPosition= -1; 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_gallery); 31 | 32 | Gallery gallery= (Gallery) findViewById(R.id.gallery); 33 | ImageAdapter imageAdapter = new ImageAdapter(this); 34 | gallery.setAdapter(imageAdapter); 35 | gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 36 | @SuppressLint("NewApi") 37 | @Override 38 | public void onItemSelected(AdapterView parent, View v,int position, long id) { 39 | AnimatorSet animatorSet = new AnimatorSet(); 40 | ObjectAnimator imgScaleUpYAnim = ObjectAnimator.ofFloat(v, "scaleY", 0.7f, 1.05f); 41 | imgScaleUpYAnim.setDuration(600); 42 | //imgScaleUpYAnim.setInterpolator(DECCELERATE_INTERPOLATOR); 43 | ObjectAnimator imgScaleUpXAnim = ObjectAnimator.ofFloat(v, "scaleX", 0.7f, 1.05f); 44 | imgScaleUpXAnim.setDuration(600); 45 | animatorSet.playTogether(imgScaleUpYAnim,imgScaleUpXAnim); 46 | animatorSet.start(); 47 | 48 | for(int i = 0;i < parent.getChildCount();i++){ 49 | if(parent.getChildAt(i) != v){ 50 | View s = parent.getChildAt(i); 51 | ObjectAnimator imgScaleDownYAnim = ObjectAnimator.ofFloat(s, "scaleY", 1.05f, 0.7f); 52 | imgScaleDownYAnim.setDuration(100); 53 | //imgScaleUpYAnim.setInterpolator(DECCELERATE_INTERPOLATOR); 54 | ObjectAnimator imgScaleDownXAnim = ObjectAnimator.ofFloat(s, "scaleX", 1.05f, 0.7f); 55 | imgScaleDownXAnim.setDuration(100); 56 | animatorSet.playTogether(imgScaleDownXAnim,imgScaleDownYAnim); 57 | animatorSet.start(); 58 | } 59 | } 60 | } 61 | 62 | @Override 63 | public void onNothingSelected(AdapterView arg0) { 64 | 65 | } 66 | }); 67 | 68 | } 69 | 70 | @Override 71 | public boolean onCreateOptionsMenu(Menu menu) { 72 | // Inflate the menu; this adds items to the action bar if it is present. 73 | getMenuInflater().inflate(R.menu.gallery, menu); 74 | return true; 75 | } 76 | 77 | @Override 78 | public boolean onOptionsItemSelected(MenuItem item) { 79 | // Handle action bar item clicks here. The action bar will 80 | // automatically handle clicks on the Home/Up button, so long 81 | // as you specify a parent activity in AndroidManifest.xml. 82 | int id = item.getItemId(); 83 | if (id == R.id.action_settings) { 84 | return true; 85 | } 86 | return super.onOptionsItemSelected(item); 87 | } 88 | public class ImageAdapter extends BaseAdapter{ 89 | 90 | private Context mContext; 91 | public ImageAdapter(Context context){ 92 | mContext = context; 93 | } 94 | public int getCount(){ 95 | return myImageIds.length; 96 | } 97 | public Object getItem(int position){ 98 | return position; 99 | } 100 | public long getItemId(int position){ 101 | return position; 102 | } 103 | @SuppressLint("NewApi") 104 | public View getView(int position, View convertView, ViewGroup parent){ 105 | ImageView imageView = new ImageView(mContext); 106 | imageView.setImageResource(myImageIds[position]); 107 | imageView.setScaleType(ImageView.ScaleType.FIT_XY); 108 | imageView.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.WRAP_CONTENT, Gallery.LayoutParams.WRAP_CONTENT)); 109 | imageView.setScaleX(0.7f); 110 | imageView.setScaleY(0.7f); 111 | return imageView; 112 | } 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/com/example/gallery/GalleryView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.gallery; 18 | 19 | import android.content.Context; 20 | import android.util.AttributeSet; 21 | import android.view.KeyEvent; 22 | import android.view.MotionEvent; 23 | import android.widget.Gallery; 24 | 25 | 26 | public class GalleryView extends Gallery { 27 | public GalleryView(Context paramContext){ 28 | super(paramContext); 29 | } 30 | 31 | public GalleryView(Context paramContext, AttributeSet paramAttributeSet){ 32 | super(paramContext, paramAttributeSet); 33 | } 34 | 35 | @Override 36 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 37 | if (e1.getX() - e2.getX() < 0.0F){ 38 | onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT,null); 39 | }else{ 40 | onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT,null); 41 | } 42 | return true; 43 | } 44 | 45 | } 46 | --------------------------------------------------------------------------------