2013-03-05 7 views
1

어떻게 이미지보기 사이에 여백을 설정합니까? 내 코드에서 루프를 사용하여 많은 이미지 뷰를 만들지 만 두 이미지 뷰 사이에 공간이 없습니다 어떻게 teo 이미지 뷰 사이에 여백을 설정합니까 ?? 프로그래밍 방식으로 두 개의 이미지 뷰 사이에 공간을 추가하는 방법 ???캡쳐 이미지를 이미지보기로 설정하는 방법

  ScrollView scroll = new ScrollView(MainActivity1.this); 
    scroll.setLayoutParams(new 
    LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
    LayoutParams.WRAP_CONTENT));  

    btnLO = new LinearLayout(MainActivity1.this); 
    LinearLayout.LayoutParams paramsLO = new 
    LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
    // button margins 
    paramsLO.setMargins(0, 0, 0, 0); 
    // button height/width *pixels* 
    paramsLO.height = 75; 
    paramsLO.width = 75; 

    btnLO.setOrientation(LinearLayout.VERTICAL); 
    btnLO.setBackgroundColor(5); // not working correctly 

    //buttons 
    for (i =0;i <reqdata.length;i++) 
     { 
      LinearLayout li=new LinearLayout(this); 
      li.setOrientation(LinearLayout.HORIZONTAL); 
      final Button b1 = new Button(MainActivity1.this); 
      final ImageView imageView = new ImageView(MainActivity1.this); 


      li.addView(b1, paramsLO);   
      li.addView(imageView, paramsLO); 
      btnLO.addView(li); 

      b1.setOnClickListener(new View.OnClickListener() 
        { 
         public void onClick(View v) 
         {    

          imgIndex = btnLO.indexOfChild(b1)/2; 

Toast.makeText(getBaseContext(),imgIndex, 
    Toast.LENGTH_SHORT).show(); 
          imageView1 = imageView; 
          Intent pictureActionIntent = new 
Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new 
    File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD,IMAGE_CAPTURE_NAME))); 

startActivityForResult(pictureActionIntent,CAMERA_PICTURE); 

          } 

        });  

     } 

    final Button b2 = new Button(MainActivity1.this); 
    b2.setText("Submit"); 
    b2.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     {       
      for (i =0;i <reqdata.length;i++) 
      { 


dbConnector.saveVisitDetail(blob[i],i,Long.valueOf(reqdata[i].getValue()) 
    .longValue()); 
      }    
     } 
    }); 
    btnLO.addView(b2, paramsLO); 
    btnLO.setGravity(Gravity.LEFT | Gravity.CENTER_HORIZONTAL); 
    scroll.addView(btnLO); 

    this.addContentView(scroll, new LayoutParams()); 

} 



@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent 
imageReturnedIntent) { 
     super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

      if (imageReturnedIntent.getExtras() != null) 
       { 
        // here is the image from camera 
        yourSelectedImage = (Bitmap) 
imageReturnedIntent.getExtras().get("data"); 
        ByteArrayOutputStream outStr = new 
ByteArrayOutputStream();     

yourSelectedImage.compress(CompressFormat.JPEG, 100, outStr); 
        blob[imgIndex] = outStr.toByteArray(); 
        yourSelectedImage = 

BitmapFactory.decodeByteArray(blob[imgIndex], 0, blob.length); 
        imageView1.setImageBitmap(yourSelectedImage); 

       } 

    } 

답변

0

봅니다 progrematicly이 방법으로 여백을 설정합니다 :

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
layoutParams.setMargins(30, 30, 30, 30); 
image.setLayoutParams(params); 
+0

을하지만 난 wherei이 정의하는 두 개의 이미지보기 –

+0

사이에 추가 WNT? 내부 forloop? –

+0

@hayyaanam : imageView1 ImageView가 동적으로 또는 xml로 만들었습니다. –

2
protected void onActivityResult(int requestCode, int resultCode, Intent ata)          
       { 
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { 
     if (resultCode == RESULT_OK) { 


      imageView = (ImageView) findViewById(R.id.imageView1); 
      Bitmap photo = (Bitmap) data.getExtras().get("data"); 
      imageView.setImageBitmap(photo) 
     }}}