gpt4 book ai didi

android - 如何在我的 android gridview 中显示来自互联网的图像并显示完整图像?

转载 作者:行者123 更新时间:2023-11-29 00:33:29 26 4
gpt4 key购买 nike

如何在 android 应用程序中显示从互联网到 gridview 的图像。在 gridview 中显示 clicl om 任何图像后,它将在从左向右滑动和向右滑动 tp left 后显示全屏图像。我已经实现了一些代码,但存在一个错误。显示填充图像后如何滑动这些图像。

图像适配器

public class ImageAdapter extends BaseAdapter {
private Context mContext;

// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.img_2, R.drawable.img_3,
R.drawable.img_4
};

// Constructor
public ImageAdapter(Context c){
mContext = c;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return mThumbIds.length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mThumbIds[position];
}

@Override
public long getItemId(int position) {

return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
//imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
}

全图:

public class FullImageActivity extends Activity {


private static final String LOGID = "CHECKTHISOUT";

private static final int SWIPE_MIN_DISTANCE = 160;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);

// get intent data
Intent i = getIntent();

// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);

ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource(imageAdapter.mThumbIds[position]);

gestureDetector = new GestureDetector(new MyGestureDetector());
}
private class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
next();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
previous();
}
} catch (Exception e) {
// nothing
}
return false;
}
public void next()
{

}
public void previous()
{

}
}
}

最佳答案

您可以在 gridview 中显示图像,然后您可以使用 viewpager 通过滑动显示全屏图像。我建议您重复使用这些图像,而不是每次都从互联网上下载它们。您可以利用可用的库,如 https://github.com/nostra13/Android-Universal-Image-Loader它将为您处理缓存机制。

关于android - 如何在我的 android gridview 中显示来自互联网的图像并显示完整图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14021200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com