Distorted background image in Android Studio

0

Personally I created an image for the background of my app, I did it according to the resolution of the smartphone I was testing, but it got distorted, then I remembered that I was using ActionBar, so the app screen gets smaller. p>

My question is the following, can you get the screen size other than Fullscreen, but with ActionBar, in the case from the actionbar down?

Am I working the right way to create the background? Type simply get the resolution of the smart and do or is there another better way?

LogCat responding to sicachester:

04-22 16:42:53.965 1256-1256/com.app.gustavo.jogodavelha E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.IllegalStateException: Could not execute method of the activity at android.view.View$1.onClick(View.java:2144) at android.view.View.performClick(View.java:2485) at android.view.View$PerformClick.run(View.java:9080) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at android.view.View$1.onClick(View.java:2139)             at android.view.View.performClick(View.java:2485)             at android.view.View$PerformClick.run(View.java:9080)             at android.os.Handler.handleCallback(Handler.java:587)             at android.os.Handler.dispatchMessage(Handler.java:92)             at android.os.Looper.loop(Looper.java:130)             at android.app.ActivityThread.main(ActivityThread.java:3683)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:507)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)             at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) at android.content.res.Resources.loadDrawable(Resources.java:1709) at android.content.res.Resources.getDrawable(Resources.java:581) at android.view.View.setBackgroundResource(View.java:7533) at com.app.gustavo.jogodavelha.Main.clickQuadrado(Main.java:45)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:507)             at android.view.View$1.onClick(View.java:2139)             at android.view.View.performClick(View.java:2485)             at android.view.View$PerformClick.run(View.java:9080)             at android.os.Handler.handleCallback(Handler.java:587)             at android.os.Handler.dispatchMessage(Handler.java:92)             at android.os.Looper.loop(Looper.java:130)             at android.app.ActivityThread.main(ActivityThread.java:3683)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:507)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)             at dalvik.system.NativeStart.main(Native Method)

    
asked by anonymous 20.04.2015 / 16:23

1 answer

2

Making any image, whether background or not, with the specific size of the device you are testing is risky. You will never be able to guarantee that the image is perfect in all scenarios. Although the devices have the same screen size, the density between them are different, which also will not guarantee the same quality of your image.

Note that in the vast majority of apps, the background of the application is "flat", that is, a solid color only.

However, if you need an image as background for your application, I recommend two options:

1) Extract one image for each density and place them in the specific folders (ldpi, mdpi, hdpi, etc.).

2) Extract a simple large image and use ImageView , with attribute scaleType as centerCrop , and apply your image to it:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/your_image"/>

    <EditText
        android:id="@+id/et_example"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
    
20.04.2015 / 20:32