Can't set the background of my EditText - java

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:
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:
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.

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!

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.

Related

how to change the entire background in android studio

Open source code that I am using
in my design render it shows me the entire background is blue but the actually app only have color on the listviews. Following is my xml code and screen shots.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b8569fee">
<TextView android:id="#+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b8569fee"
android:textSize="24dp"/>
<TextView
android:id="#+id/device_address"
android:layout_width="match_parent"
android:background="#b8569fee"
android:layout_height="wrap_content"
android:textSize="12dp" />
</LinearLayout>
render
actually app:
I tried to change the textview layout height to match_parent, but it still didn't work, so what do i need to do to change the entire background?
Thnaks
What's happening here is that your XML file is defining the layout for an individual element in that list view, then the list view is programatically applying this XML to build a new view onto the list whenever a new BLE device is discovered. The size of each list element is defined externally, by whatever is putting each of your views into the list. Therefore, when you put match_parent in the LinearLayout and expect that to fix your issue, it does not because it only fills the area allotted by the listview. The fix is to change the background color within the listview itself, which is not done in this XML.
I'd need to see to more code to know exactly how to do this, but I am going to take a shot in the dark and assume that you are using a ListActivity, as in the Google BluetoothLeGatt example. In this case, you can change the background color of the ListView using something like:
getListView().setBackgroundColor(Color.rgb(86, 159, 238));
Placed in the onCreate method.
The view indicated is only a view inside the layout that contains the ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b8569fee">
<TextView android:id="#+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b8569fee"
android:textSize="24dp"/>
<TextView
android:id="#+id/device_address"
android:layout_width="match_parent"
android:background="#b8569fee"
android:layout_height="wrap_content"
android:textSize="12dp" />
</LinearLayout>
You must change the background color to the layout that contains the ListView
android:background="#b8569fee"

Positioning icon half above layout

Recently, designers in my company liked creating half-above elements in layouts for Android apps. I've been struggling for a while trying to make these elements behave as good as possible, but I'm already tired of it. Is there any way of positioning views like on this image
with an assumption that if user touch row/card it became "checked" and this black dot icon became visible (second click makes it invisible of course).
You can do something like this:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#+id/circle_view"
android:background="#android:color/holo_blue_bright">
<android.support.v7.widget.CardView
android:id="#+id/second_view"
android:layout_width="100dp"
android:layout_height="match_parent"/>
</FrameLayout
<View
android:id="#+id/circle_view"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="#android:color/holo_red_dark"
android:layout_marginEnd="-8dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
second_view is endOf circle_view so if circle_view is gone second_view will align to startOf parent.
circle_view should have marginEnd set to negative value of its width divided by two

How to add image in android studio without following errors?

When I try to insert any photo to the android studio.
Following errors happen:
Image shows blank
Unable to resize
So please help me! I am suffering from this type of thing from 2days.
The xml layout:
<?xml version="1.0" encoding="utf-8"?>
<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="20dp"
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.buckydroid.image.MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_centerHorizontal="true"
android:src="#mipmap/hehe"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
The values set for margins here, combined with:
android:layout_height="20dp"
Are squeezing your image down really small. The layout frame is only 20dp tall and if you're using the default values for activity_vertical_margin, your using 16dp as margin on either side of the image, leaving no room for your actual image.
Use the res\drawable folder(s) for UI graphics and res\mipmap for the application icon. See e.g. this tutorial.
Then instead of
android:src="#mipmap/hehe"
you shoud use
android:src="#drawable/hehe"
Bitmaps in drawable folder(s) should be simple bitmaps and you can use different sizes for different screen densities. This is explained in more detail in the documentation but basically you can have several drawable folders each containing a different size version of the same bitmap for the different densities like:
res/drawable-mdpi/graphic.png // bitmap for medium-density
res/drawable-hdpi/graphic.png // bitmap for high-density
res/drawable-xhdpi/graphic.png // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png // bitmap for extra-extra-high-density
Android will automatically pick the most suitable version. You just need to provide them. (Or use just one version of each bitmap if they seem to scale well enough.)
Only the application icons should be mipmaps with all the different sizes in one file.

Android Studio: Graphics are cut

I have the Views attached to each other in the following order:
Activity->RelativeLayout->RelativeLayout->Text
When I change the Y of one of the Text attached to the inner RelativeLayout, parts of it are cut.
Here's a screenshot:
http://s28.postimg.org/ypmvrjz25/image.png
I'm coding purely in Java, no XML.
What's going on?
It looks like one layout is overlapping on another because the menu bar is pushing it down. If you just want the text centered I would suggest setting that in the parameters like so.
android:gravity="center"
This places the text in the center if that is what you want.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView12"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
As #Jonathan Whalen suggested you probably have some overlap, I suggest you to change your relative layouts background color to see wich one is overlapping the text. Also try to not use fixed height for the layouts but use wrap_content instead, as fixed dims are frequently the cause of layouts overlap.

Android placing multiple bitmaps in imageview

I have multiple ImageViews which are transparent and are meant to over lap one another. I am aligning then to one another but one problem presist. How can I set the order in which they are layered? Ive tried revising the code in both xml and how the images are set in the actual java code...
I have tried FrameLayout but maybe Im not using it right...here is my implementation:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".RadarActivity" >
<ImageView
android:id="#+id/imageview_topo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageview_counties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
No matter what I do...imageview_topo is always placed on top. Even in the code i have instantated topo first and retrieved its image first!
Thank you!
I referred a site here that says:
If multiple child views exist, then they are drawn, in order, one atop
the other. This means that the first view added to the frame layout
will display on the bottom of the stack, and the last view added will
display on top.
You can check this site too: http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/
May be i can help you more if you show the screenshot of your UI.

Categories