I made this button:
http://i.stack.imgur.com/QkrMD.png
But the image is much bigger than it should be (it should be a quarter of its current size). I made various sizes of the image and put each into the respective drawable folder.
The size of the icon should be:
http://i.stack.imgur.com/12E8r.png
How do I scale the image down to the size I need to do be (as it is in the regular drawable size)?
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3,056"
android:drawableLeft="#drawable/ic_arrow_up_b"
android:background="#color/gray"
android:padding="15dp"
/>
I don't think you should use a Button in this case. You should use a ImageButton. Maybe they work the same but if you are putting an image in a button, using ImageButton makes a lot of sense.
If you use an ImageButton, the image is always stretched to fit the size of the button. That means if you want to make the image smaller, you just make the button smaller.
Related
I am designing an android app and I need to implement the following interface. I need a round border around this number. For the round border I am using an image with a circle with a gradient border. For the numbers I am using the textview. The problem that I have is that when I debug it, the numbers extremely sharp and clean but the circle is not that sharp. The borders look quite rough. I took a screenshot of it but on the phone the thing is much more evident. I also noticed this when I was using an image and a background. The picture in the background was much more clear than the image on the screen. How can I fix this.
This is the XML that I am using
<ImageView
android:layout_width="270dp"
android:layout_height="270dp"
android:id="#+id/imageView"
android:background="#drawable/b"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
Not sure about that image sharpness but you should consider on below points with your ImageView,
Setting the image to the ImageView using android:src="..." rather than android:background="...". src= makes it scale the image maintaining aspect ratio!
You should also use android:adjustViewBounds="true" to make the ImageView resize itself to fit the resealed image.
You can change the way it default scales images using the android:scaleType parameter, use android:scaleType="centerCrop" and see if it gets more clear.
I need to make four imageButtons in my app. Whenever I insert a JPEG image into Android Studio and put it on the imageButton, the button just grows in size so that the image doesn't fit on the button.
I need the button to just stay the same size that I've made it and need the image to fit nicely and be centered on the button. I've tried everything. Does anyone know how to do this? Can this be done with any sized image of any format?
To make your image fill ImageButton then use - android:scaleType="fitXY"
<ImageButton
android:id="#+id/TextButton"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="0.5"
android:scaleType="fitXY"
android:src="#drawable/jpeg_image" />
I'm trying to display an image but for some reason it's only giving me a smaller (unreadable) version. Is there a way to display the image full screen and enable zooming in/out? I used a fragment to display the image--do I need to create another class to extend the particular fragment...? Here is the imageview:
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:scaleType="centerInside"
android:src="#drawable/rules" />
If the image is not appering in the full screen, probably there is an issue with the ImageView container. The ImageView may be "filling the parent" but the parent is not filling the screen.
Other issue may be the scaleType, are you sure your image is the correct size? If you want to stretch it you have to change the scaleType.
How about this :
Get screen dimensions in pixels
and then something like this (IF you want to resize the image):
Android image on tablets and phones
This is not a complete answer to your question but the programming should be straightforward once you know the size of the screen and the size of the image.
I am trying to use the 9-patch technique to create the button.
It looks almost great in the Layout Window of Eclipse
When I run it in the emulator it shows up like this:
Here is the actual PNG image
Selector XML
<item android:drawable="#drawable/splash_facebook_button" />
Button Code in Layout
<Button
android:id="#+id/button1"
android:layout_width="208dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dip"
android:background="#drawable/splash_facebook_button_selector"
android:text="Sign up with Facebook" />
Looks to me like it's not treating the image as a 9-patch. Have you saved it with the .9.png extension?
Edit:
Had a better look at the actual image and I don't think you've quite got it set up correctly. The bottom and right border define where the content will go (in this case you want it over to the right, with a bit of padding).
The top and left define the areas that will be stretched when the image is scaled. In this case you want it to be areas of constant blue that get stretched, rather than the logo. I've updated the image with an example of how to do this:
This works for me!
I currently working on my personal project in Android. I'm quite a newbie in android development well it's been a months since I've started to self study this but I just can't focus on this one. Well, so here's my problem, first I will discuss what I've made so far:
I've placed a 6 ImageView for each tableRow (six table rows) in a table layout which make it a 6x6 ImageView.
each of the imageView has a default image icon (the default icon from the android drawable).
Once I clicked the ImageView I will change it's Image using setImageDrawable.
the default icon of the android is sized smaller than the images I've placed in which I think 36x36 pixels is the default icon (the android default) wherein my images are in size of 80x80 pixels.
Now here's the problem:
Once I've clicked the image it will successfully changes the image but will also resize the imageView into the size of my image(80x80 px).
well how do I get over this? I've tried setting the ImageView's scale type into fitXY but it has done nothing still my the imageView is resized.
I've also tried changing the wrap_content into fill_parent but nothing also happens (well I just think that it may solve the problem lol)
Here's the property of my ImageView:
<ImageView android:scaleType="fitXY"
android:id="#+id/imageView1"
android:src="#drawable/image0"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</ImageView>
Any help please? Thanks in advance!
you can set the fix size for the image view into the xml file or by coding through for e.g. here in xml file
<ImageView android:scaleType="fitXY"
android:id="#+id/imageView1"
android:src="#drawable/image0"
android:layout_height="90dp"
android:layout_width="120dp">
</ImageView>
so all image are display with the size 120*90 so when you change the picture it will fit into this imageview