Closed iielse closed 6 years ago
public void show(ImageView i, List<ImageView> imageGroupList, final List<Uri> urlList) {
之前设计的是 第二个imageGroupList和第三个参数urlList是对应关系,且顺序也需要对应,且点击触发show的imageView必须是 imageGroupList中的元素 限制太多
public void show(ImageView i, SparseArray<ImageView> imageGroupList, final List<Uri> urlList) {
思考后发现,把第二个入参改成了 SparseArray类型,imageGroupList的key(position) 映射 urlList中的url地址要灵活很多, 点击触发show的imageView依旧需要在imageGroupList中,来确认初始位置。 这样设计更适合聊天界面来查看图片列表。
SparseArray
要改变的地方 3处
/** * @param i 被点击的ImageView * @param imageGroupList * @param urlList 被加载的图片url列表,数量必须大于等于 imageGroupList.size。 且顺序应当和imageGroupList保持一致 */ public void show(ImageView i, SparseArray<ImageView> imageGroupList, final List<Uri> urlList) { if (i == null || imageGroupList == null || urlList == null || imageGroupList.size() < 1 || urlList.size() < imageGroupList.size()) { String info = "i[" + i + "]"; info += "#imageGroupList " + (imageGroupList == null ? "null" : "size : " + imageGroupList.size()); info += "#urlList " + (urlList == null ? "null" : "size :" + urlList.size()); throw new IllegalArgumentException("error params \n" + info); } initPosition = -1; for (int x = 0; x < imageGroupList.size(); x++) { if (imageGroupList.get(imageGroupList.keyAt(x)) == i) { initPosition = imageGroupList.keyAt(x); break; } } if (initPosition < 0) { throw new IllegalArgumentException("param ImageView i must be a member of the List <ImageView> imageGroupList!"); } ... }
private boolean setDefaultDisplayConfigs(final ImageView imageView, final int pos, boolean hasPlayBeginAnimation) { boolean isFindEnterImagePicture = false; ViewState.write(imageView, ViewState.STATE_ORIGIN).alpha(0).scaleXBy(1.5f).scaleYBy(1.5f); if (mImageGroupList.get(pos) != null) { // 这里 ImageView originRef = mImageGroupList.get(pos); if (pos == initPosition && !hasPlayBeginAnimation) {
@Override public void onPageSelected(int position) { iSource = adapter.mImageSparseArray.get(position); if (iOrigin != null) { iOrigin.setVisibility(View.VISIBLE); } if (mImageGroupList.get(position) != null) { // 这里 iOrigin = mImageGroupList.get(position); if (iOrigin.getDrawable() != null) iOrigin.setVisibility(View.INVISIBLE); }
调用
conversationAdapter1 = ConversationAdapter1().apply { cb = object : ConversationAdapter1.Callback { override fun onPictureClick(view: ImageView, uri: Uri, uriList: List<Uri>, position: Int) { // view 被点击的imageView // uri 被点击的imageView对应展示的图片地址信息 // uriList 一整个要展示的图片列表 vImageWatcher.show(view, SparseArray<ImageView>().apply { put(uriList.indexOf(uri), view) }, uriList) } } }
效果
之前设计的是 第二个imageGroupList和第三个参数urlList是对应关系,且顺序也需要对应,且点击触发show的imageView必须是 imageGroupList中的元素 限制太多
思考后发现,把第二个入参改成了
SparseArray
类型,imageGroupList的key(position) 映射 urlList中的url地址要灵活很多, 点击触发show的imageView依旧需要在imageGroupList中,来确认初始位置。 这样设计更适合聊天界面来查看图片列表。要改变的地方 3处
调用
效果