1

Buenas tardes chicos, esta vez quisiera me colaboraran con un proceso que realizo y es el de tomar (n) cantidad de fotos y ponerlas dinámicamente en un LinearLayout, el problema es que, cuando las agrego, queda un espcio bastante amplio entre cada item de esta forma:

Interfaz después de tomar la foto y cargada en el LinearLayout

Formulario Normal, antes de tomar foto: introducir la descripción de la imagen aquí

Este es el codigo Java de mi proceso:

   public void TomarFoto(View view){
        nombre_imagen = GetNombre();
        Intent intento1 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File foto = new File(getExternalFilesDir(null), nombre_imagen + ".jpg");
        intento1.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(foto));
        startActivityForResult(intento1, TAKE_PICTURE);
    }

Y este es el XML de donde se agregan las imagenes:

                    <LinearLayout
                        android:id="@+id/Fotografias"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical">

                        <Button
                            android:text="Tomar Foto"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="27dp"
                            android:id="@+id/BtnTomarFoto"
                            style="@style/Widget.AppCompat.Button.Colored"
                            android:onClick="TomarFoto"/>

                    </LinearLayout>
                </ScrollView>

Agradezco vuestra colaboración!!

2
  • las imagenes la añades a un ImageView si es asi prueba añadir algo asi ... <ImageView ... android:scaleType="fitXY" /> el 10 feb. 2017 a las 20:13
  • @Felipe agrega el layout completo donde se tiene el ImageView para agregar la foto por favor.
    – Jorgesys
    el 10 feb. 2017 a las 20:57

2 respuestas 2

1

de tanto consultar, al fin encontré la solución

ImageView la_imagen = new ImageView(this);
            la_imagen.setLayoutParams(new DrawerLayout.LayoutParams(300, 300));
            la_imagen.setScaleType(ImageView.ScaleType.CENTER_CROP);
            la_imagen.setPadding(10, 10, 10, 10);

            Bitmap bitmap1 = BitmapFactory.decodeFile(getExternalFilesDir(null) + "/" + nombre_imagen + ".jpg");
            la_imagen.setImageBitmap(bitmap1);
            LinearLayout layout = (LinearLayout) findViewById(R.id.Fotografias);
            layout.addView(la_imagen);

Agradezco vuestros comentarios y ayuda que me sirvieron bastante! :)

0

Quizas te oriente mas este codigo:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Get the widgets reference from XML layout
        ImageView iv = (ImageView) findViewById(R.id.iv);
        TextView tv = (TextView) findViewById(R.id.tv);

        //Get the ImageView LayoutParams and assign ImageView height to 300 pixels
        iv.getLayoutParams().height = 300;

        //Get the ImageView LayoutParams and assign ImageView width to 300 pixels
        iv.getLayoutParams().width = 300;

        //************ Uncomment any section and comment other sections to view effect *********

        /*************************** ScaleType = CENTER ********************************/
        //Center the image in the view, but perform no scaling.
        //iv.setScaleType(ImageView.ScaleType.CENTER);
        //tv.setText("ScaleType = CENTER");
        /******************************************************************************/

        /*************************** ScaleType = CENTER_CROP ********************************/
        /*
            Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions
            (width and height) of the image will be equal to or larger than the corresponding
            dimension of the view (minus padding).
        */
        //iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
        //tv.setText("ScaleType = CENTER_CROP");
        /******************************************************************************/

        /*************************** ScaleType = CENTER_INSIDE ********************************/
        /*
            Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions
            (width and height) of the image will be equal to or less than the corresponding
            dimension of the view (minus padding).
         */
        //iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        //tv.setText("ScaleType = CENTER_INSIDE");
        /******************************************************************************/

        /*************************** ScaleType = FIT_CENTER ********************************/
        //Scale the image using CENTER.
        //iv.setScaleType(ImageView.ScaleType.FIT_CENTER );
        //tv.setText("ScaleType = FIT_CENTER");
        /******************************************************************************/

        /*************************** ScaleType = FIT_END ********************************/
        //Scale the image using END.
        //iv.setScaleType(ImageView.ScaleType.FIT_END);
        //tv.setText("ScaleType = FIT_END");
        /******************************************************************************/

        /*************************** ScaleType = FIT_START ********************************/
        //Scale the image using START.
        //iv.setScaleType(ImageView.ScaleType.FIT_START);
        //tv.setText("ScaleType = FIT_START");
        /******************************************************************************/

        /*************************** ScaleType = FIT_XY ********************************/
        //Scale the image using FILL.
        //iv.setScaleType(ImageView.ScaleType.FIT_XY);
        //tv.setText("ScaleType = FIT_XY");
        /******************************************************************************/

        /*************************** ScaleType = MATRIX ********************************/
        //Scale using the image matrix when drawing.
        iv.setScaleType(ImageView.ScaleType.MATRIX);
        tv.setText("ScaleType = MATRIX");
        /******************************************************************************/
    }
}

puedes mirar el comportamiento en este link el numero 5.

Puedes ir descomentado para ir provando.

Si te fijas se esta usando ScaleType = MATRIX comenta esa parte y descomenta ScaleType = FIT_XY.

Algo asi.

..//
        /*************************** ScaleType = FIT_XY ********************************/
        //Scale the image using FILL.
        iv.setScaleType(ImageView.ScaleType.FIT_XY);
        tv.setText("ScaleType = FIT_XY");
        /******************************************************************************/

        /*************************** ScaleType = MATRIX ********************************/
        //Scale using the image matrix when drawing.
        //iv.setScaleType(ImageView.ScaleType.MATRIX);
        //tv.setText("ScaleType = MATRIX");
        /******************************************************************************/
    }

Espero sea lo que buscas.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.