Android

동적으로 뷰생성 (예시 )

Machine_웅 2020. 8. 26. 18:22
728x90
반응형
 private void showPhotoList(){

        layout_List.removeAllViews();
        hs_Scrollview.scrollTo(0,0);

        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

        for(int i=0; i<ImageArr.size(); i++) {  //for(int i=0; i<ItemArray.size(); i++) {
            final int position = i;

            View body = null;
            body = inflater.inflate(R.layout.item_photo, null);
            Button btn_item = (Button) body.findViewById(R.id.btn_delete);
            ImageView photo = (ImageView) body.findViewById(R.id.image);

            Glide.with(JobAlbaEditActivity.this)
                    .asBitmap()
                    .apply(new RequestOptions()
                            .override(300, 300)
                            .centerCrop()
                            .dontAnimate()
                            .placeholder(R.drawable.join_photo)
                            .dontTransform())
                    .load(bitmapToByte(ImageArr.get(i)))
                    .into(photo);

            btn_item.setTag(i);
            btn_item.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ItemArray.remove((int) v.getTag());
                    ImageArr.remove((int) v.getTag());
                    showPhotoList();
                }
            });

            layout_List.addView(body, i);
        }
        isLoad = false;
    }
728x90
반응형