Control over ImageView, Android Studio

1

Good afternoon guys, this time I would like to collaborate with a process that I do and it is to take (n) number of photos and put them dynamically in a LinearLayout, the problem is that, when I add them, there is a wide space between each item in this way:

Normal form, before taking picture:

This is the Java code of my process:

   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);
    }

And this is the XML where the images are added:

                    

                    <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>

I appreciate your collaboration!

    
asked by Felipe Mendieta Perez 10.02.2017 в 21:07
source

2 answers

1

from so much consulting, I finally found the solution

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);

I appreciate your comments and help that helped me a lot! :)

    
answered by 13.02.2017 / 14:20
source
0

Maybe this code will guide you more:

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");
        /******************************************************************************/
    }
}

You can look at the behavior in this link the number 5.

You can go decompressed to be provando.

If you notice you are using ScaleType = MATRIX comment that part and uncomment ScaleType = FIT_XY .

Something like that.

..//
        /*************************** 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");
        /******************************************************************************/
    }

I hope it is what you are looking for.

    
answered by 10.02.2017 в 21:25