问题描述
我正在尝试制作一个网格视图库应用程序。当用户点击图像时,会显示完整图像。我只是无法理解我将如何实现ImageSlider并将图像保存到我现有项目中的图库中。
这是MainActivity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super。的onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView =(GridView)findViewById(R.id.grid);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override $ b $ public void onItemClick(AdapterView<?> parent,View view,int position,long id){
Intent i = new Intent(getApplicationContext(),FullImageActivity.class);
i.putExtra(id,position);
startActivity(i);
}
});
$ b这是我的ImageAdapter,包含图片:
public class ImageAdapter extends BaseAdapter {
ImageView imageView;
私有上下文上下文;
public String Images [] = {(http://www.fashionlady.in/wp-content/uploads/2016/03/creative-punjabi-mehndi-design-2016.jpg) ,
(https://lumiere-a.akamaihd.net/v1/images/uk_toystory_chi_woody_n_5b5a006f.png?region=0,0,300,300),
(https://lumiere-a.akamaihd .net / v1 / images / open-uri20150422-20810-10n7ovy_9b42e613.jpeg),
(http://www.wetpaint.com/wp-content/uploads/2015/11/toy-story-20th -anniversary.jpg),
(http://i.imgur.com/4IZMjx3.jpg)};
public ImageAdapter(Context c){
context = c; };
@Override
public int getCount(){
return Images.length;
}
@Override
public Object getItem(int position){
return Images [position];
}
@Override
public long getItemId(int position){
return 0;
$ b @Override
public View getView(int position,View convertView,ViewGroup parent){
ImageView imageview = new ImageView(context);
imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageview.setLayoutParams(new GridView.LayoutParams(240,240));
Picasso.with(context).load(Images [position])。placeholder(R.drawable.loading2).error(R.drawable.nointernet).into(imageview);
return imageview;
$ / code $ / pre
$ b $ p这是我的FullImageActivity: public class FullImageActivity extends AppCompatActivity {
TouchImageView img;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setTitle(ViewPager);
setContentView(R.layout.activity_full_image);
意图i = getIntent();
TouchImageView img = new TouchImageView(this);
int position = i.getExtras()。getInt(id);
ImageAdapter adapter = new ImageAdapter(this);
列表< ImageView> images = new ArrayList< ImageView>();
img =(TouchImageView)findViewById(R.id.img);
images.add(img);
img.setMaxZoom(4f);
Picasso.with(getApplicationContext())。load(adapter.Images [position])。into(img);
请帮助我。
解决方案你可以通过点击图片时添加动画代码来实现这一点
看到这可能是有帮助的:
I am trying to make a grid view gallery app. When a user clicks on an image, the full image is displayed. I just can't understand how I would implement ImageSlider and save the image to the gallery in my existing project.
This is MainActivity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = (GridView) findViewById(R.id.grid);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getApplicationContext(),FullImageActivity.class);
i.putExtra("id", position);
startActivity(i);
}
});
}
This is my ImageAdapter that contains Images:
public class ImageAdapter extends BaseAdapter {
ImageView imageView;
private Context context;
public String Images[] = {("http://www.fashionlady.in/wp-content/uploads/2016/03/creative-punjabi-mehndi-design-2016.jpg"),
("https://lumiere-a.akamaihd.net/v1/images/uk_toystory_chi_woody_n_5b5a006f.png?region=0,0,300,300"),
("https://lumiere-a.akamaihd.net/v1/images/open-uri20150422-20810-10n7ovy_9b42e613.jpeg"),
("http://www.wetpaint.com/wp-content/uploads/2015/11/toy-story-20th-anniversary.jpg"),
("http://i.imgur.com/4IZMjx3.jpg")};
public ImageAdapter (Context c){
context= c; };
@Override
public int getCount() {
return Images.length;
}
@Override
public Object getItem(int position) {
return Images[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageview = new ImageView(context);
imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageview.setLayoutParams(new GridView.LayoutParams(240,240));
Picasso.with(context).load(Images[position]).placeholder(R.drawable.loading2).error(R.drawable.nointernet).into(imageview);
return imageview;
}
}
This is my FullImageActivity:
public class FullImageActivity extends AppCompatActivity {
TouchImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("ViewPager");
setContentView(R.layout.activity_full_image);
Intent i = getIntent();
TouchImageView img = new TouchImageView(this);
int position = i.getExtras().getInt("id");
ImageAdapter adapter = new ImageAdapter(this);
List<ImageView> images = new ArrayList<ImageView>();
img = (TouchImageView) findViewById(R.id.img);
images.add(img);
img.setMaxZoom(4f);
Picasso.with(getApplicationContext()).load(adapter.Images[position]).into(img);
Please help me.
解决方案 you can do that by add animation code to image when clickedsee this may be is helpful :http://www.viralandroid.com/2016/02/slide-down-and-slide-up-animation-in-android.htmlhttp://www.vogella.com/tutorials/AndroidAnimation/article.html
这篇关于用Picasso实现ImageSlider GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!