1

I have this in my fragment xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.gelasoft.answeringball.MainActivity$PlaceholderFragment" 
    android:background="@drawable/wg_blurred_backgrounds_14"
    >

    <ImageView
        android:id="@+id/sphereIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:contentDescription="@string/magicBallDescr"
        android:src="@drawable/rsz_31mystic" />

    <LinearLayout
        android:id="@+id/table"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/sphereIcon"
        android:orientation="vertical" >

        <TextView 
            android:id="@+id/txtAnswer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        />

        <EditText
            android:id="@+id/txtQuestion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:hint="@string/textHint"
            android:inputType="textMultiLine"
            android:lines="6" />

        <Button 
            android:id="@+id/btnAsk"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:text="@string/btnAskQ"     
            android:paddingEnd="@dimen/activity_vertical_margin"      
         />

    </LinearLayout>
</RelativeLayout>

and here is how it looks:

enter image description here

Now I would like to set a different background image on the EditText, so I edited the xml and make it like:

<EditText
    android:id="@+id/txtQuestion"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:hint="@string/textHint"
    android:inputType="textMultiLine"
    android:lines="6" 
    android:background="@drawable/background"/>

But Now the background I set on the EditText is taking the wholw LinearLayout space.

Here is how it looks in the editor after the changes:

enter image description here

Why is it taking the whole place and hiding the button?

What am I missing here? I'm sure it is something pretty small, but I'm not able to spot it.

chility
  • 746
  • 1
  • 9
  • 22
  • 3
    What is the size of background image? Seems like there id `Out of Memory` error. – vjdhama Apr 27 '14 at 11:12
  • 1
    try cleaning your project after the change, also make sure your editText id is the same as in your activity code, and you are using the correct xml in setContentView – SacreDeveloper Apr 27 '14 at 11:14
  • @vjdhama Oh. It is 273 508bytes. Ok The one problem is fixed, but why it takes the whole `LinearLayout` instead of the `EditText`? – chility Apr 27 '14 at 11:15
  • See this : http://stackoverflow.com/questions/18693639/change-background-color-of-edittext-in-android and – vjdhama Apr 27 '14 at 11:17

2 Answers2

2

You're suffering from an out of memory exception, as visible in the last few lines of your stacktrace.

The solution would be to reduce the size of the drawable being used as a background. It's just an EditText, and it's small size doesn't warrant a high resolution file as a background.
This can be done using a variety of image editing software, from Photoshop to Microsoft Paint.
With Paint:
Step 1: Open image in Paint.
Step 2: Click on the "Resize" button at the top, next to your toolbox.
Step 3: Reduce the size of your image to an appropriate value.
Step 4: Save the image in your drawable folders.
Step 5: If you're using Eclipse, right-click on your project and click on "Refresh"
Step 6: Launch your app again.

Now for the expansion of the EditText:

You're EditText height is set to wrap_content. When you set an image as it's background, that too becomes it's content. Hence, you're EditText bloats itself to accomodate it's new background.

A solution would be to hardcode the height like
android: layout_height="30dp" though the ability to use this depends on your requirements.

Abraham Philip
  • 648
  • 9
  • 18
  • Ok, I just fixed it, but why the background picture of `EditText` takes the whole `lLinearLayout` hiding even the button? – chility Apr 27 '14 at 11:17
2

I am not sure but i guest that your background image so big. you can try small width and height type image replace of that. Hopefully you can solve this problem. Best of luck!