FlipViewPager 对item实现左右对折滑动翻页效果
《FlipViewPager 对每一条item实现左右对折滑动翻页效果》,解决左右滑动和上下滑动的事件分发处理机制。
内部实现如下:用ListView试下,对listview设置adapter,这个adapter继承BaseFlipAdapter<Friend>
,然后对每一个item进行view处理,部分代码如下:
class FriendsAdapter extends BaseFlipAdapter<Friend> {
private final int PAGES = 3;
private int[] IDS_INTEREST = {R.id.interest_1, R.id.interest_2, R.id.interest_3, R.id.interest_4, R.id.interest_5};
public FriendsAdapter(Context context, List<Friend> items, FlipSettings settings) {
super(context, items, settings);
}
@Override
public View getPage(int position, View convertView, ViewGroup parent, Friend friend1, Friend friend2) {
final FriendsHolder holder;
if (convertView == null) {
holder = new FriendsHolder();
convertView = getLayoutInflater().inflate(R.layout.friends_merge_page, parent, false);
holder.leftAvatar = (ImageView) convertView.findViewById(R.id.first);
holder.rightAvatar = (ImageView) convertView.findViewById(R.id.second);
holder.infoPage = getLayoutInflater().inflate(R.layout.friends_info, parent, false);
holder.nickName = (TextView) holder.infoPage.findViewById(R.id.nickname);
for (int id : IDS_INTEREST)
holder.interests.add((TextView) holder.infoPage.findViewById(id));
convertView.setTag(holder);
} else {
holder = (FriendsHolder) convertView.getTag();
}
switch (position) {
// Merged page with 2 friends
case 1:
holder.leftAvatar.setImageResource(friend1.getAvatar());
if (friend2 != null)
holder.rightAvatar.setImageResource(friend2.getAvatar());
break;
default:
fillHolder(holder, position == 0 ? friend1 : friend2);
holder.infoPage.setTag(holder);
return holder.infoPage;
}
return convertView;
}
@Override
public int getPagesCount() {
return PAGES;
}
private void fillHolder(FriendsHolder holder, Friend friend) {
if (friend == null)
return;
Iterator<TextView> iViews = holder.interests.iterator();
Iterator<String> iInterests = friend.getInterests().iterator();
while (iViews.hasNext() && iInterests.hasNext())
iViews.next().setText(iInterests.next());
holder.infoPage.setBackgroundColor(getResources().getColor(friend.getBackground()));
holder.nickName.setText(friend.getNickname());
}
class FriendsHolder {
ImageView leftAvatar;
ImageView rightAvatar;
View infoPage;
List<TextView> interests = new ArrayList<>();
TextView nickName;
}
}
运行效果:
相关代码
- 闹钟AlarmAndMusic 滑动调整时间和页面旋转风车效果
- FlipViewPager 对item实现左右对折滑动翻页效果
- 高仿网易云音乐客户端的Home页面切换Tabhost
- 几种常用Android Progress效果
- 高仿QQ空间 侧滑Menu效果且换肤功能
- RotateMenu简单地旋转菜单控件
- WheelMenu 安卓大转盘实现
- StackOverView Android 5.0 任务管理器控件
- 完整漫画App 源码
- 轮播头像的library