《FlipViewPager 對每一條item實現左右對摺滑動翻頁效果》,解決左右滑動和上下滑動的事件分發處理機制。
內部實現以下:用ListView試下,對listview設置adapter,這個adapter繼承BaseFlipAdapter<Friend>
,而後對每個item進行view處理,部分代碼以下:
class FriendsAdapter extends BaseFlipAdapter<Friend> {html
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};ide
public FriendsAdapter(Context context, List<Friend> items, FlipSettings settings) {
super(context, items, settings);
}spa
@Override
public View getPage(int position, View convertView, ViewGroup parent, Friend friend1, Friend friend2) {
final FriendsHolder holder;rest
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);code
for (int id : IDS_INTEREST)
holder.interests.add((TextView) holder.infoPage.findViewById(id));htm
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;
}ip
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());
}get
class FriendsHolder {
ImageView leftAvatar;
ImageView rightAvatar;
View infoPage;
List<TextView> interests = new ArrayList<>();
TextView nickName;
}
}