Giter VIP home page Giter VIP logo

gallerypager's Introduction

GalleryPager

利用ViewPager实现Gallery效果,中间控件放大效果

Using Gallery to achieve ViewPager, on both sides of the display edge, animation zoom effect

版本号:1.1

使用非常简单:

1.创建布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.sherwin.gallerypager.GalleryViewPagerLayout
        android:id="@+id/gallery_pager_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </com.sherwin.gallerypager.GalleryViewPagerLayout>

</RelativeLayout>

2.继承GalleryViewPgerAdapter适配器,并实现其中的抽象方法,getView(View contentView, int position),可以对数据进行绑定,由于contentView已经被设置过Tag,所以这里不建议用ViewHolder

public class MyGalleryViewPgerAdapter extends GalleryViewPgerAdapter{
	/**
	 * 数据集
	 */
	private List<Integer> dataList;
	
	public MyGalleryViewPgerAdapter(Context context,List<Integer> dataList,GalleryViewPagerLayout galleryViewPager) {
		super(context, galleryViewPager);
		this.dataList=dataList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dataList==null?0:dataList.size();
	}

	@Override
	public void getView(View contentView, int position) {
		ImageView imageView=(ImageView) contentView.findViewById(R.id.image);
		imageView.setImageResource(dataList.get(position));
	}

	@Override
	public int getItemLayoutId() {
		return R.layout.item;
	}
}

3.创建Activity,并创建适配器

galleryViewPagerLayout = (GalleryViewPagerLayout) findViewById(R.id.gallery_pager_layout);
/**
 * 创建适配器
 */
MyGalleryViewPgerAdapter adapter = new MyGalleryViewPgerAdapter(this, imgList, galleryViewPagerLayout);
/**
 * 设置适配器
 */
galleryViewPagerLayout.setAdapter(adapter);

至此完成配置,具体在使用中可以根据自定义的Adapter来实现不同的布局和不同的功能需要

gallerypager's People

Contributors

sherwin-ye avatar

Stargazers

WilsonL avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.