【开源】ImageCoverFlow

ImageCoverFlow

  •  https://github.com/dolphinwang/ImageCoverFlow/archive/master.zip

    介绍:

    效果不错的画廊控件 可以设置画廊一次可见图片的张数,和其他第三方Gallery控件不同的是,该控件直接继承自View,而不是sdk中的Gallery控件。如果想获得包含demo的可运行代码,请在本站的下载链接中下载。

    运行效果:

使用说明:

首先设置命名空间:

1
    xmlns:imageCoverFlow="http://schemas.android.com/apk/res-auto"

在布局文件中添加ImageCoverFlow

1
2
3
4
5
6
7
8
9
10
11
12
13
    <com.dolphinwang.imagecoverflow.CoverFlowView
        android:id="@+id/coverflow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        imageCoverFlow:coverflowGravity="center_vertical"
        imageCoverFlow:coverflowLayoutMode="wrap_content"
  
        imageCoverFlow:reflectionGap="10dp"
        imageCoverFlow:reflectionHeight="30%"
        imageCoverFlow:visibleImage="3" >
    </com.dolphinwang.imagecoverflow.CoverFlowView>

注意作者在github上的描述是有问题的,没有

imageCoverFlow:enableReflection="true"

imageCoverFlow:reflectionShaderEnable="true"

两个属性,作者根本就没有定义。

另外,visibleImage属性的值必须为基数,否则会报出异常,这个异常是作者有意抛出的。

在Activity中初始化:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.example.imagecoverflowdemo;
  
import java.util.ArrayList;
 
import com.dolphinwang.imagecoverflow.CoverFlowAdapter;
import com.dolphinwang.imagecoverflow.CoverFlowView;
import com.dolphinwang.imagecoverflow.CoverFlowView.CoverFlowGravity;
import com.dolphinwang.imagecoverflow.CoverFlowView.CoverFlowLayoutMode;
 
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
 
public class MainActivity extends ActionBarActivity {
    private ArrayList<Bitmap> imgList; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         
        CoverFlowView<MyCoverFlowAdapter> mCoverFlowView = (CoverFlowView<MyCoverFlowAdapter>)this.findViewById(R.id.coverflow);
 
          
        imgList = new ArrayList<Bitmap>();
        imgList.add(BitmapFactory.decodeResource(this.getResources(), R.drawable.a));
        imgList.add(BitmapFactory.decodeResource(this.getResources(), R.drawable.b));
        imgList.add(BitmapFactory.decodeResource(this.getResources(), R.drawable.c));
        imgList.add(BitmapFactory.decodeResource(this.getResources(), R.drawable.d));
        imgList.add(BitmapFactory.decodeResource(this.getResources(), R.drawable.d));
         
        MyCoverFlowAdapter adapter = new MyCoverFlowAdapter();
        mCoverFlowView.setAdapter(adapter);
      
         
    }
     
    public class MyCoverFlowAdapter extends CoverFlowAdapter{
        public int getCount(){
            return 5;
        }
 
        public  Bitmap getImage(int position){
            return imgList.get(position);
        }
    }
 
 
}

 

相关代码

  • BooheeScrollView
  • 一个搜狐视频画廊效果的demo

posted on 2015-04-27 09:20  wasdchenhao  阅读(117)  评论(0)    收藏  举报

导航