0

I tried to set a background image for the main activity in android (using xamarin). The image is shown in the design but when I emulate to my phone (Galaxy S4) is not show. Here is the code. What is wrong here ?

        <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/home"
        android:scaleType="fitXY" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:columnCount="1"
            android:layout_gravity="bottom"
            android:minHeight="250dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:minHeight="125dp">
                <Space
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Button 1"
                    android:layout_gravity="center" />
                <Space
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Button 2" />
                <Space
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:minHeight="125dp">
                <Space
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Button 3"
                    android:layout_gravity="center" />
                <Space
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Button 4" />
                <Space
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
            </LinearLayout>
        </GridLayout>
    </LinearLayout>
</RelativeLayout>
cozmin-calin
  • 421
  • 2
  • 6
  • 19

1 Answers1

2

It maybe to big. Show in console for error like this: Bitmap too large to be uploaded into a texture (4350x2448, max=4096x4096)

Try to put the image to drawable-nodpi

Android background image memory usage

Community
  • 1
  • 1
iwanlenin
  • 210
  • 4
  • 11
  • I'm using visual studio 2015 for this android project and I don't have the folder "drawable-nodpi" in solution, I have only the folder "drawable". I tried with a small image (720x1280) because this one is (1080x1920) and it's working. It's related to image resolution but how can I change it to fit in all screens ? Thanks – cozmin-calin Apr 22 '16 at 09:11
  • You can add this folder to your solution inside the Resources folder :-) – iwanlenin Apr 22 '16 at 09:20
  • I tried also this but it doesn't know ho to switch between them. – cozmin-calin Apr 22 '16 at 09:34
  • Try to remove the image from another drawable folders. – iwanlenin Apr 22 '16 at 09:45
  • I tried your layout on my VS 2015 with the drawable-nodpi with a big image. it works. Another option ist to set android:largeHeap="true" inside your Manifest – iwanlenin Apr 22 '16 at 10:11
  • For which screen size? I tried for 5" screen size and it's not working but for 5.1 and 5.5" is working – cozmin-calin Apr 22 '16 at 10:52
  • You're right. I was stupid. I added the folder drawable-nodpi and I added my image into this folder but I forgot to remove the image from drawable folder. Now it's working perfectly. Thank you – cozmin-calin Apr 22 '16 at 11:01