Distorted background image in Android Studio

Asked

Viewed 2,031 times

0

Personal created an image for the background of my app, I made it according to the resolution of the smartphone I was testing, but it was distorted, then I remembered I was using Actionbar, so the screen of the app gets smaller.

My question is the following, has how to get the screen size that is not in Fullscreen, but with Actionbar, in case from the actionbar down?

Am I working the right way in creating the background? Like I just take the resolution of 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)

  • I don’t understand why Voce wants to get the screen size down from the action bar.

  • Hello friend... well maybe I’m wrong but here’s the thing. I created a bakground according to the size of the screen, as if it was going to be fullscreen, but it has the action bar, so the background starts from the Action Bar becoming smaller the area of the application other than the fullscreen one. I suppose that’s the loyivo of the image I made gets a little out of shape, got kind of "squeezed"

  • I suppose that’s the problem*

  • post a picture of the normal image, and after how it looked in the app

1 answer

3

Making any image, whether background or not, with the specific size of the device you are testing is very risky. You can never ensure that the image is perfect in all scenarios. As much as 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 application background is "flat", that is, a solid color only.

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

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

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

<?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>
  • Thanks, but I think my Android Studio is configured wrong or whatever, because I can’t find the drawable folders with the resolutions, there’s only one drawable that is empty

  • @Ablon these folders are not created automatically, it depends on the developer creating them. Check out the documentation on how to create them: http://developer.android.com/guide/topics/resources/providing-resources.html#Alternativeresources

  • 1

    Ata, good is that I saw in the tutorials that they were already created when starting the project. At home I will try, thank you!

  • Well I created them, before, I was setting an image in the Imagebutton that was in the drawable folder (the only one I had), so now I created the folders with the different resolutions and put in each one the image according to the DPI. But the app breaks when the image should appear, there is some different way to do when working with several drawable folders?

  • @Ablon what error appears in Logcat?

  • Is in my question...

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.