android 图片预览动画,Android图片上传实现预览效果

本文介绍了在Android中如何实现图片预览动画和多图上传功能。首先,通过分析需求,包括从相册选择图片和拍照上传。接着,详细讲述了使用NoScrollGridView展示图片,自定义ViewPager进行图片浏览,以及适配器PictureAdapter的使用。同时,还涵盖了从相册选择图片、添加到自定义数组、预览和选择限制等操作。最后,提到了预览图片的实现和UI设计。
摘要由CSDN通过智能技术生成

首先具体分析一下,实现的功能,其中需求分析是必不可少的,需求、逻辑清除之后,再上手写代码,思路会很清晰。

1.多图上传首先得选择图片(这里项目需求是既可以拍照上传也可以从相册中选择)

2.拍照上传很简单了网上也有很多例子,调用照相机,返回uri,获取图片

3.从相册中选择图片

3.1 获取手机中的所有图片

3.2 将图片存到自定义图片数组中显示

3.3 自定义ViewPager浏览图片

主要的逻辑大体是这样,下面具体看一下实现:

一、首先看一下界面:

android:id="@+id/noScrollgridview"

android:layout_marginLeft="@dimen/smaller_space"

android:layout_marginRight="@dimen/smaller_space"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:horizontalSpacing="3dp"

android:listSelector="@color/transparent"

android:numColumns="3"

android:scrollbars="none"

android:layout_gravity="center"

android:layout_marginTop="@dimen/smaller_space"

android:verticalSpacing="5dp" />

是一个 NoScrollGridView,项目需要,所以用了不滚动的GridView,大家用GridView也是一样的。

noScrollgridview = (GridView) findViewById(R.id.noScrollgridview);

noScrollgridview.setSelector(new ColorDrawable(Color.TRANSPARENT));

/*新建传值给adapter*/

if (file == null) {

picAdapter = new PictureAdapter(this, 0, null);

} else {

//添加失败的图片到数组中

for (int i=0;i

ImageItem imageItem = new ImageItem();

imageItem.setImagePath(file.getMulFailFilePaths()[i].trim());

Bimp.tempSelectBitmap.add(imageItem);

}

/*上传失败传值给adapter*/

picAdapter = new PictureAdapter(this, 2, file);

}

这个是初始化图片数组,适配器(新建、上传失败、上传成功的图片我用的都是一个adapter)

ImageItem是图片的模型,下面有它的属性

//从图库选择的图片model

public class ImageItem extends File implements Serializable {

@Id

public String imageId; //图片id

public String thumbnailPath;

public String imagePath; //图片路径

private Bitmap bitmap;

public boolean isSelected = false;

public String getImageId() {

return imageId;

}

public void setImageId(String imageId) {

this.imageId = imageId;

}

public String getThumbnailPath() {

return thumbnailPath;

}

public void setThumbnailPath(String thumbnailPath) {

this.thumbnailPath = thumbnailPath;

}

public String getImagePath() {

return imagePath;

}

public void setImagePath(String imagePath) {

this.imagePath = imagePath;

}

public boolean isSelected() {

return isSelected;

}

public void setSelected(boolean isSelected) {

this.isSelected = isSelected;

}

[java] view plain copy print?

/*根据图片路径获取图片的

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值