Android - 有多个“PhotoView”的照片选择?

时间:2017-04-06 11:48:14

标签: android android-photoview

我使用以下代码创建了多个“PhotoView”和变量:

public void SayfaEkle(int id) throws JSONException {
    LayoutInflater inflater = this.getLayoutInflater();
    FrameLayout f;
    int photos = 0;


    switch (id){
        case 1:
            photos = 5;

            final Drawable bitmap = ContextCompat.getDrawable(this,R.drawable.complex);
            f = (FrameLayout) inflater.inflate (R.layout.foto_layout_1, null);
            int pageId = addView(f);
            sayfa_sablon_ids.put("Sayfa_"+pageId, id);


            Map<String, PhotoView> fotograflar = new HashMap<String, PhotoView>();
            for( int z = 1; z<= photos; z++ ) {
                int idResource = getResources().getIdentifier("photo_" + z + "_area", "id", getPackageName());

                final PhotoView photoview = (PhotoView) f.findViewById(idResource);

                photoview.setScaleType(ImageView.ScaleType.CENTER_CROP);

                photoview.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        photoview.setImageDrawable(bitmap);
                        Log.d("OnClick"," yes ");
                    }
                });
                fotograflar.put("pView"+z,photoview);
            }
            sayfalar.put("Sayfa_"+pageId,fotograflar);
        break;
        case 2:
            f = (FrameLayout) inflater.inflate (R.layout.foto_layout_2, null);
            Log.d("id", "IKI --------------------");
        break;
        default:
            f = (FrameLayout) inflater.inflate (R.layout.foto_layout_1, null);
    }
}

但是在这段代码中我选择了照片。我希望用户通过点击“PhotoView”来选择这张照片。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

尝试

 //Make bitmap object final
 final Bitmap bitmap = //replace getBitamp();

    int photos = 5;
    Map<String, PhotoView> ppp = new HashMap<String, PhotoView>();
    for( int z = 1; z<= photos; z++ ) {
        int idResource = getResources()
                         .getIdentifier("photo_"+z+"_area", "id", getPackageName());

        PhotoView photoView = (PhotoView) f.findViewById(idResource);
        photoView.setImageDrawable(bitmap);
        photoView.setScaleType(ImageView.ScaleType.CENTER_CROP);


        photoView.setOnClickListener(new OnClickListener() {

          public void onClick(View v) {
            photoView.setImageBitmap(bitmap);
             //select....
          }
    });

    ppp.put("pView"+z,photoView);