Android 如何在imageview中显示所有图像
我是android新手,尝试编写代码来显示从API获取的海报,问题是在运行它之后,然后它只显示一张海报。请给我一些建议 1.poster_image.xmlAndroid 如何在imageview中显示所有图像,android,Android,我是android新手,尝试编写代码来显示从API获取的海报,问题是在运行它之后,然后它只显示一张海报。请给我一些建议 1.poster_image.xml <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/poster" android:layout_width="500dp" android:layout_height="60dp" /> 2.Main
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/poster"
android:layout_width="500dp"
android:layout_height="60dp" />
2.MainActivity.java
public class MainActivity extends AppCompatActivity {
ArrayList<String> moviesList = new ArrayList<>();
ImageView mImageView;
String url = "https://api.themoviedb.org/3/movie/popular?api_key=(MY API KEY)";
String image_url = "http://image.tmdb.org/t/p/w185";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.poster_image);
mImageView = (ImageView) findViewById(R.id.poster);
// Fetch Data from API
RequestQueue requestQueue = Volley.newRequestQueue(this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("results");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject movies = jsonArray.getJSONObject(i);
String poster = movies.getString("poster_path");
moviesList.add(poster);
Log.i("IS", String.valueOf(moviesList));
}
for (int j = 0; j < moviesList.size(); j++) {
Picasso.with(getApplicationContext())
.load(image_url + moviesList.get(j))
.into(mImageView);
Log.i("I", image_url + moviesList.get(j));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error", "Wrong");
}
});
requestQueue.add(jsonObjectRequest);
}
}
public类MainActivity扩展了AppCompatActivity{
ArrayList moviesList=新的ArrayList();
图像视图;
字符串url=”https://api.themoviedb.org/3/movie/popular?api_key=(我的API密钥)“;
字符串图像\u url=”http://image.tmdb.org/t/p/w185";
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、海报图片);
mImageView=(ImageView)findviewbyd(R.id.poster);
//从API获取数据
RequestQueue RequestQueue=Volley.newRequestQueue(this);
JsonObjectRequest JsonObjectRequest=新的JsonObjectRequest(Request.Method.GET,url,null,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
JSONArray JSONArray=response.getJSONArray(“结果”);
for(int i=0;i
您必须创建一个recylerview以显示来自服务器的图像列表。
使用Glide、毕加索和Fresco从服务器加载图像。
通过这个链接 如果使用ListView,我应该怎么做?我需要适配器吗?感谢不要使用listView使用RecyclerView创建自定义回收器适配器使用listView或带有适配器的RecyclerView(首选)来显示图像视图列表,几乎每个示例都显示有图像列表,因此很容易找到有任何示例吗?