Android 将imageview设置为水平滚动视图

Android 将imageview设置为水平滚动视图,android,android-imageview,horizontalscrollview,Android,Android Imageview,Horizontalscrollview,嗨,我有一个网址,给我2个图像链接。我必须下载图像并设置图像。我正在使用水平滚动视图,直到获取图像url并使用异步任务下载图像为止。有人能告诉我如何将图像设置为水平滚动视图吗 public void fetchImageUrl(){ String url="http://apps.aspelec.com/cms/api/UploadImageAndChangeComplaintStatus?companyid=1&callrecordid=13"; StringReque

嗨,我有一个网址,给我2个图像链接。我必须下载图像并设置图像。我正在使用水平滚动视图,直到获取图像url并使用异步任务下载图像为止。有人能告诉我如何将图像设置为水平滚动视图吗

public void fetchImageUrl(){
    String url="http://apps.aspelec.com/cms/api/UploadImageAndChangeComplaintStatus?companyid=1&callrecordid=13";
    StringRequest request=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            System.out.println(response);
            getJsonUrl(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("ErrorListner=",error.getMessage());
        }
    });
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(request);

}
public void getJsonUrl(String response){
    try {
        JSONArray jArray = new JSONArray(response);
        ArrayList<String> imgurl=new ArrayList<>();
        for(int i=0;i<1;i++){
          String dummyurl=jArray.getJSONObject(i).getString("ImagePath");
            System.out.println("dummy url=="+dummyurl);
            imgurl.add(dummyurl);
            setView(imgurl);
        }
    }catch (JSONException e){

    }
}
public void setView(ArrayList<String> imgUrl){
    for(int j=0;j<imgUrl.size();j++){
        vi=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v=vi.inflate(R.layout.custome_serverdownloadedimageview,null,false);
        img=(ImageView)v.findViewById(R.id.customserverdownlodedimg);
        new DownloadImage(img).execute(imgUrl.get(j));
        //Picasso.with(this).load(imgUrl.get(j)).resize(100,100).into(img);
    }
}
public void fetchImageUrl(){
字符串url=”http://apps.aspelec.com/cms/api/UploadImageAndChangeComplaintStatus?companyid=1&callrecordid=13";
StringRequest=newStringRequest(request.Method.GET,url,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
System.out.println(响应);
getJsonUrl(响应);
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Log.e(“ErrorListner=,error.getMessage());
}
});
RequestQueue RequestQueue=Volley.newRequestQueue(this);
添加(请求);
}
public void getJsonUrl(字符串响应){
试一试{
JSONArray jArray=新JSONArray(响应);
ArrayList imgurl=新的ArrayList();

对于(inti=0;i你可以这样做

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/customserverdownlodedimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"/>
</LinearLayout>
horizontalScrollView=(horizontalScrollView)findViewById(R.id.horizontal_网格);
int[]images=newint[]{R.drawable.image1,R.drawable.image2,….R.drawable.image10};
LinearLayout sv=(LinearLayout)findViewById(R.id.水平容器);
对于(int i=0;i
public void setView(ArrayList imgUrl){
serverDownloadedImageView=(LinearLayout)findViewById(R.id.serverDownloadedImageView);
serverDownloadedImageView.removeAllViews();

对于(int j=0;jp请看我还有其他东西要在xml文件上显示,最后我将显示图像..我的水平滚动视图位于xml文件的底部..您可以添加一个水平循环视图来代替滚动视图,它不仅工作得很好,而且对用户非常友好感谢您的建议…我将尝试使用当时我正在读有关它的书。
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/customserverdownlodedimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"/>
</LinearLayout>
 horizontalScrollView = (HorizontalScrollView)findViewById(R.id.horizontal_grid);
        int[] images = new int[]{R.drawable.image1, R.drawable.image2, ....R.drawable.image10};
        LinearLayout sv = (LinearLayout) findViewById (R.id.horizontal_container);
        for (int i=0 ; i<images.length; i++){
            ImageView iv = new ImageView (this);
            LinearLayout.LayoutParams imageViewLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,  ViewGroup.LayoutParams.MATCH_PARENT);
            iv.setPadding(4,0,0,0);
            iv.setImageResource(images[i]);
            iv.setLayoutParams(imageViewLayoutParams);
            sv.addView(iv);
        }
    <HorizontalScrollView
        android:id="@+id/horizontal_grid"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="40">
        <LinearLayout
            android:id="@+id/horizontal_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >
        </LinearLayout>

    </HorizontalScrollView>
public void setView(ArrayList<String> imgUrl){

serverDownloadedImageView = (LinearLayout)findViewById(R.id.serverDownloadedImageView);
serverDownloadedImageView.removeAllViews();
    for(int j=0;j<imgUrl.size();j++){

     ImageView img = new ImageView(this);

        new DownloadImage(img).execute(imgUrl.get(j));
        //Picasso.with(this).load(imgUrl.get(j)).resize(100,100).into(img);
    serverDownloadedImageView.addView(img,j)

    }
}