Resize image to screen size

1

I created a ViewA class where I get two images from the drawable folder and draw on the screen with draw ();

public class ViewA extends View {

private Bitmap img1;
private Bitmap img2;

public ViewA(Context context){
    super(context);
    img1 = BitmapFactory.decodeResource(getResources(), R.drawable.imagem01);
    img2 = BitmapFactory.decodeResource(getResources(), R.drawable.imagem02);
}

public void draw(Canvas canvas){
    super.draw(canvas);
    canvas.drawBitmap(img1, 0, 0, null);
    canvas.drawBitmap(img2, 0, 0, null);
}

}

and here is MainActtivity

public class MainActivity extends AppCompatActivity {

private ViewA view;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    view = new ViewA(this);
    setContentView(view);

    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

}

}

It's full screen, however, when you take pictures and draw them on the screen, assuming it's a 1920x1080 resolution image, the images will be cropped and only a part of the image will appear. I wanted to know if you can put these whole images on the screen !! without being cut.

    
asked by anonymous 12.11.2016 / 01:04

1 answer

1

If the idea is to put a background image on the activity do the following:

sua_activity.xml

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imgBack"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:scaleType= "fitCenter"          <- escolha aqui o tipo de ajuste
        android:src="@drawable/imagem"/>

     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        ...         <- controles que vão sobrepor a imagem de fundo

     </LinearLayout>

</FrameLayout>

See the documentation for fit types in ImageView.ScaleType

If you want to have more control over the image, create a class derived from ImageView     

12.11.2016 / 14:08