android scrollview 内容居中,DiscreteScrollView

一个用RecyclerView实现的画廊效果,被选中item居中放大,效果很自然。

依赖:compile 'com.yarolegovich:discrete-scrollview:1.0.3'

使用

1. xml中添加DiscreteScrollView

android:layout_width="match_parent"

android:layout_height="wrap_content" />

2. 设置adapterDiscreteScrollView scrollView = findViewById(R.id.picker);

scrollView.setAdapter(new YourAdapterImplementation());

apiscrollView.getCurrentItem(); //returns adapter position of the currently selected item or -1 if adapter is empty.

scrollView.scrollToPosition(int position); //position becomes selected

scrollView.smoothScrollToPosition(int position); //position becomes selected with animated scroll

scrollView.setItemTransitionTimeMillis(int millis); //determines how much time it takes to change the item on fling, settle or smoothScroll

设置transformer 实现移动动画,和viewpager的transformer功能是一样的scrollView.setItemTransformer(transformer);

public interface DiscreteScrollItemTransformer {

/**

* In this method you apply any transform you can imagine (perfomance is not guaranteed).

* @param position is a value inside the interval [-1f..1f]. In idle state:

* |view1|  |currentlySelectedView|  |view2|

* -view1 and everything to the left is on position -1;

* -currentlySelectedView is on position 0;

* -view2 and everything to the right is on position 1.

*/

void transformItem(View item, float position);

}

监听scrollView.setScrollStateChangeListener(listener);

public interface ScrollStateChangeListener {

void onScrollStart(T currentItemHolder, int adapterPosition); //called when scroll is started, including programatically initiated scroll

void onScrollEnd(T currentItemHolder, int adapterPosition); //called when scroll ends

/**

* Called when scroll is in progress.

* @param scrollPosition is a value inside the interval [-1f..1f], it corresponds to the position of currentlySelectedView.

* In idle state:

* |view1|  |currentlySelectedView|  |view2|

* -view1 is on position -1;

* -currentlySelectedView is on position 0;

* -view2 is on position 1.

*/

void onScroll(float scrollPosition);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值