我的Android Java没有在屏幕外加载照片?

时间:2016-01-28 17:37:50

标签: java android android-layout

我的Android Java代码从Facebook获取照片并显示它们。它会更改每张照片的X和Y值,每行显示4个。这很好,但是当打印Y值大于屏幕高度的照片时,它会停止打印它们。没有错误,但我无法向下滚动才能看到它们。有解决方案吗?

   public void onCompleted(GraphResponse response) {
                    JSONObject photos = response.getJSONObject();
                    JSONArray data = photos.optJSONArray("data");
                    int x1 = 0;
                    int y1 = 0;
                    boolean first1 = true;
                    for(int i =0;i<data.length();i++) {
                        if(x1==0&&first1==false){
                            x1 = 310;

                        }
                        else if(x1==310){
                            x1=620;

                        }
                        else if(x1==620){
                            x1=930;
                        }
                        else if(x1==930){
                            x1=0;
                            y1 = y1+310;
                        }

                        first1=false;
                        JSONObject link = data.optJSONObject(i);
                        String link2 = link.optString("picture");
                        ImageView imageView = new ImageView(getApplicationContext());
                        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(300, 300);
                        params.leftMargin = x1;
                        params.topMargin = y1;
                        URL path = null;
                        try {
                            path = new URL(link2);
                        } catch (MalformedURLException e) {
                            e.printStackTrace();
                        }
                        Bitmap image = null;
                   GridView grid1 =    (GridView)           findViewById(R.id.gridView1);
                        try {
                            image =     BitmapFactory.decodeStream(path.openConnection().getInputStream());
                            image = Bitmap.createScaledBitmap(image, 300, 300, false);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        imageView.setImageBitmap(image);
                        RelativeLayout rl = (RelativeLayout) findViewById(R.id.RL1);

                        rl.addView(imageView, params);
                    }

0 个答案:

没有答案