I am currently working on a basic app using eclipse as my IDE. I am currently having trouble setting an image as my background. I was following a tutoral which told me to place my image in the drawable-mdpi folder and name it as icon. I have tried this but it keeps on placing in the andriod icon instead even when i delete the andriod icon image. Is there a better way of doing this?
Thanks
try this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal" android:background="#drawable/background"></LinearLayout>
background is a .png file. with borders draw around it with Nine9Patch.
Hope this helps
Related
Recently, while working on some projects, I've had a rather annoying problem when coding the user interface of my application. The problem is, some controls (usually a floating action button or a regular button) render strangely. It's hard for me to explain exactly how it looks - but here's an example of how it shows the floating action button to look like in the designer:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:baselineAligned="false"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:src="#drawable/ic_baseline_add_24"
android:layout_height="wrap_content"/>
</LinearLayout>
Now, the thing is, I don't have any weird or special code added, the XML code is as pure as it gets, so I have no idea why I am having these strange rendering problems.
Here is how it rendered the following button:
Code:
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_gravity="bottom"
android:textAllCaps="false"
android:layout_margin="30dp"
app:cornerRadius="30dp"
android:id="#+id/submitButton"
android:backgroundTint="#color/turquoise"
/>
Image:
A solution would be greatly appreciated!
Cheers,
Tom
Solution is simple u just need to restart your android rendering engine. I provided Image for your context . In android studio top right corner above layout display there is Toggle issue panel click on that and u will see one box in the bottom showing rendering issue restart rendering engine and that will restart your android studio. and u good to go. try this solution and let me know your issue is solved or not.
note: In my Image I already restarted so there is no option for restart rendering engine .but in yours's U may be find hope so.
Image
I'm trying to set background image for my activity like this:
<LinearLayout
android:id="#+id/container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/login_background"
android:orientation="vertical">
which looks great in the preview in intellij
but in genymotion it looks black:
after trying to change the name of the file, the size of the file and trying various export methods from photoshop, I'm clueless.
Any ideas?
Have you tried another genymotion config yet?
Or have you tried it on a real Device?
I would suggest to use some other Configuration first, according to this post it could help.
https://github.com/facebook/fresco/issues/298
PS: I know not a real answer, got not enough reputation yet, thought i could help anyway.
After playing with the issue more I truly don't know what was the problem. After trying the same image in different activity it started to show even without modified the genymotion settings.
I am very new to android development, and have only read and completed the first guide in the android development site. The problem I have been having is that I can not put a picture in an activity. I have the picture in my drawables folder. I just don't know how to get it on the screen. Any help is appreciated.
since you followed the tutorial, I presume you have a screen that says Hello World.
that means you have some code in your layout xml that looks like this
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
you want to display an image, so instead of TextView you want to have ImageView. and instead of a text attribute you want an src attribute, that links to your drawable resource
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cool_pic"
/>
I'll Explain how to add an image using Android studio(2.3.3). First you need to add the image into res/drawable folder in the project. Like below
Now in go to activity_main.xml (or any activity you need to add image) and select the Design view. There you can see your Palette tool box on left side. You need to drag and drop ImageView.
It will prompt you Resources dialog box. In there select Drawable under the project section you can see your image. Like below
Select the image you want press Ok you can see the image on the Design view. If you want it configure using xml it would look like below.
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/homepage"
tools:layout_editor_absoluteX="55dp"
tools:layout_editor_absoluteY="130dp" />
You need to give image location using
app:srcCompat="#drawable/imagename"
When you have image into yours drawable gallery then you just need to pick the option of image view pick and drag into app activity you want to show and select the required image.
copy the image that you want to show in android app and paste in drawable folder. given below code
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/image"
/>
Ok I have created a background image in Inkscape. Exported that image and it looks correct, when I open it from Eclipse. However, when I build the project and apply that background to the Layout, it shows the complete opposite in the designer and on the device.
Here is what the image is supposed to look like. Correct background
Here is what the image looks like in the Eclipse Designer.Incorrect background.
Here is my Xml on a brand new Xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_view_bg"
android:orientation="vertical" >
</LinearLayout>
I am utterly confused on this one. Any help is greatly appreciated.
You are most likely using a theme where the background in dark. As your background gradient is transparent the black background is showing through.
Switch to a light theme.
I am trying to get the same look and feel as the API demo in my application, but the fonts appear smaller. I have not set any fonts for my application. Is there some settings i am missing on the fonts?
The image with black background is the Api Demo which came along with the SDK samples. I am working on Android 2.2. The image with the white background is my application. I would like to know how to achieve the spacing between each of the rows in the list and the font as in the API Demos list.Can someone kindly help me with this. Thanks in advance.
<ListView android:id="#+id/MyListView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:divider="#android:color/transparent"
android:dividerHeight="10.0sp"/>
[1][1] [2][2]
view this link for change font in listview