android - 如何使用来自服务器(Android)的数据创建缩略图照片库?
问题描述
我想创建一个微型照片库。通过单击缩略图,我想以全尺寸显示照片。从服务器我得到 2 个不同的 url。一张用于微型照片,另一张用于全尺寸照片。
这是我关于照片的活动:
public class GalleryActivity extends MyActivity {
private ServerAPI server;
private ArrayList<Photo> gallery ;
List<String> mThumbIds;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery);
gallery = new ArrayList<Photo>();
server= new ServerAPI(this);
galleryGridView = findViewById(R.id.galleryGridView);
loadDataSource();
GalleryAdapter adapter = new GalleryAdapter(GalleryActivity.this, gallery);
galleryGridView.setAdapter(adapter);
}
private void loadDataSource() {
//here get data from server and popolate the Photo array
}
private final class GalleryAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<Photo> images = new ArrayList<Photo>();
}
public GalleryAdapter(Context c, ArrayList<Photo> gallery) {
mContext = c;
images = gallery;
}
@Override
public int getCount() {
return images.size();
}
@Override
public Photo getItem(int i) {
return images.get(i);
}
@Override
public long getItemId(int i) {
return images.get(i).id;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
...
...
...
...
}
public class Photo{
public int id;
public String url;
public String url_thumb;
public String text = "";
public Photo(int id, String url, String url_thumb, String text) {
this.id= id;
this.url = url;
this.url_thumb = url_thumb;
this.text= text;
}
}
画廊活动.xml
<GridView
android:id="@+id/galleryGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:gravity="center">
</GridView>
layout_image_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#21bfaf">
<ImageView
android:id="@+id/imageId"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:scaleType="fitXY"/>
</RelativeLayout>
在单击缩略图时,我会打开一张全尺寸的照片。
谢谢,
解决方案
推荐阅读
- html - 用于文本的 HTML 编码创建区域
- angular - 组件在角度 6 中自动更改其位置
- c++ - 是否可以在 IPC 中模拟 Signal & slot?
- postgresql - 使用返回表、休眠、postgresql 的函数
- django-rest-framework - 在序列化器中清理 django api
- java - 关于 Java Util Map Entry Class 的问题
- php - Slim PHP 框架 3.0:访问 .phtml 模板路由时出现 404 错误
- python - 在 django 中重新组合只返回一个石斑鱼 - 不在重新组合的列表上迭代
- sql-server - 将多个 mdf 文件附加到 SQL Server 实例或提取数据并将其保存到新数据库
- python - django csv 自动导入