ImageButton with external image? - android

I'm searching a way to put my own image as an ImageButton. There is the src thing but it accepts only icons i thing. Any help?

This is pretty fundamental stuff which would be covered if you ran through tutorials.
There's more to it, but the general common procedure would be to include any images you want to use in your res/drawable folder for the project. Then, you'd usually reference the image in XML something like this:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myimage" />

Related

ImageView doesn't appear

I have dragged an ImageView to layout and I selected the picture. But when I execute the application, It doesn't appear. What can I do to solve this ?
ImageView XML code;
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
app:srcCompat="#mipmap/idlepoor_moneys"
android:id="#+id/imageView4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
Add this property in Your image View
android:src="#mipmap/idlepoor_moneys"
Remove the following line from your code
app:srcCompat="#mipmap/idlepoor_moneys"
As allready said change
app:srcCompat="#mipmap/idlepoor_moneys"
to
android:src="#mipmap/idlepoor_moneys"
Also I recommend to put your images in the #drawable folder. The mipmap is where app icons are stored when making an app.
app:src="#drawable/idlepoor_moneys"
You can easily find the drawable from your project map. If you can't find it you can always right click the folder to get the path to it.

How do I insert an image in an activity with android studio?

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"
/>

ImageView of PNG doesn't appear (maybe it's too big)

Inside my AlertDialog I've an ImageView, when I choose to show the android:src="#drawable/logo_small" (a png around 64x64px in every folders /hdpi /ldpi ect..) all works fine. Instead when I show android:src="#drawable/logo_big" (it's just ONE png of 1417x1417pixel and 593KB in the drawable root folder) the image doesn't appear.
The layout:
<?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:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id="#+id/imageLogoBig"
android:layout_width="30dp"
android:layout_height="30dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/logo_big" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="#drawable/gplay_logo" />
</LinearLayout>
The imageLogoBig doesn't show in the upper example and in the lower example:
<ImageView
android:id="#+id/imageLogoBig"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/logo_big" />
I just discovered while I was writing the question that if I delete from drawable root directory the image logo_big and if I copy it in drawable-hdpi, drawable-ldpi, drawable-mdpi and drawable-xhdpi, all works fine. And this is strange because the other image: imageView1, is only in the drawable folder (but is 172x60px) and is showed correctly.
Why is this happening? Any suggest? (For example put logo_big only in drawable-xhdpi...)
I solved moving logo_big png image only to the directory drawable-xhdpi, don't know really why, but it works now.
This can be for a number of reasons, one is the name of the file not being compliant, that's clearly not your case but I'm pretty sure it's of many others like me that would reach this question when looking for an answer.
In a nutshell, underscores '_' are permitted but hyphens '-' are not, maybe because these are used to add resource qualifiers to file names (or at least directories).
This is something easy to remember, but even easier to forget. So, to put an example, this file didn't work:
poa-sample.png
And the solution was to rename it to:
poa_sample.png
I leave this here JFTR, because as stupid as this is, it a made me waste a lot of time and try everything else before. You'd expect Android Studio to give an error at build time, as it would do with an invalid variable identifier for example, but as of today it won't give you even a proper warning.
try renaming your image file to "logobig", without an underscore and see if that works. Even though file-based resource names allow underscores, i've had trouble occasionally

Best way to put vectorized symbols on button? Wingdings button title

Suppose I want to draw simple icon on the button surface. Let it be the cross or some letter.
What is the best way to do this? Can I use wingdings or webdings font on button?
As Android uses Unicode (utf-8) you can use any sign defined there, as long your font supports that. Just use copy and paste. The better solutions i think is using ImageButton using images from your drawables folder. This folder can be found in project/res/drawables or via Ecplipse Package-Explorer and you should use this to copy and paste your files in place (png, gif and jpg are supported)
In XML layout file a image is assigned the following way to an ImageButton
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
See also:
http://developer.android.com/reference/android/widget/ImageButton.html
http://developer.android.com/guide/topics/resources/providing-resources.html
http://developer.android.com/training/multiscreen/screendensities.html

Where Should I put the PNG file relate to ImageButton in Android?

I'm very new to Android.
I created a ImageButton. The main.xml includes code segment as following.
<ImageButton
android:id="#+id/button1"
android:layout_width="50px"
android:layout_height="50px"
android:src="#drawable/cat"
android:layout_x="50px"
android:layout_y="52px"
>
Where do i have to put the "cat.png" i have. Do i need to rename it to something else?
Put it in the res/drawable/ folder in your Android project. Keep the name cat.png
you can simply put in any one folder it will work no need to change xml for that.

Categories

Resources