I have a very simple question.
I have been asked by my company to make the actionbar just a simple imageview. So no icon, no title and no buttons at all. I've created a custom actionbar, and the imageview is up there just fine. I have attached a link to an image of my layout, and the emulator on the right. They want the imageview to be like it is in the layout. But in the emulator it comes up small.
My question is simply: is there a way I can make the imageview fit like it is in the layout there, and of course have it fit for different devices too - or, must the graphic designer simply create a banner that fits the size of an actionbar. If so, I looked at android's iconography and saw the height should be 48dp. but what about the width? And won't different devices have different width? Or will i be able to make sure it is stretched across the whole width of the screen. I've tried match parent in my xml but of course it won't do anything now because it doesn't want to stretch the height of the actionbar.
Thanks alot
https://www.dropbox.com/s/1tek8ptar3j76d4/Screenshot%202015-02-27%2009.55.30.png?dl=0
Get your graphic designer make you a 9 patch png that will expand in the middle while keeping its proportions then simply add this line of code:
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.your_nine_patch_png));
More on nine patch images here: http://developer.android.com/tools/help/draw9patch.html
Here is the trick!
yourImageView.setGravity(Gravity.FILL_HORIZONTAL);
Happy coding! ;D
Related
I want your help regarding a problem.
I am creating an app, and I have like 9 images which I want to appear horizontally across the screen.
Check this image
But in the above screenshot, as you can see, I have only 8 images and the screen seems to be full, I want to add one more image of number 9.
Here is my activity_main.xml (hastebin link)
It will be more helpful if you could explain to me a bit rather than just fixing it, also, could you please suggest other fixes, this is the college project I am working on.
Thank you for your precious time :)
If the images are fixed, you can set your LinearLayout width (the ones that contains the images) as "match_parent" and add the attribute weightSum = 9 . That will make its width the same as the container. Then you set each image width to 0 and add weight= 1.
This will make each image width 1/9 of the parent, no matter the size of the device screen.
It will look something like the answer of user9209780.
For the RecyclerView elements I use CardView. I would like to make each item of the list
A background image is not a problem to prepare. I do not specify the size of the CardView, I have specified match_parent and wrap_content. I do not know what size to make a background image, so that it looks fine on the phones and on the tablets.
Any suggestions? Or do I need to specify the width and height of the item for phones and tablets and already do the background for them? How do experienced developers? vector drawable is not interested yet
To create resizable images you should check out 9-patch. It's the easiest way to fit the image to different ratios. Here you can find a post that better explains how to use it.
To create the image you can either use an online tool, or use the tool provided in Android Studio.
I have a little problem, if someone could tell why:
1. My background image in my toolbar's button appear really small ?
2. When I import some images, it show a blank image in the xxhdpi, xhdpi, hdpi, mdpi thumbnails.
Screenshot:
Android Studio screenshot
Thank's in advance!
A <Button> is primarily meant to display text, though it does also allow you to display images. However, it allows you to display images above, below, to the left of, or to the right of the text. That is why you were able to get an image using android:drawableTop... this is the image to display above your text.
Probably you just want to use <ImageView> here instead, and specify your image using the android:src attribute.
Another solution would be to populate your toolbar using a menu instead of manually adding views, but perhaps that's not possible for your requirements.
Instead of Button, You can use ImageButton in this case and you can give android:src="[your icon]"
Note :
Try to give min 48dp width and height to button
I am making a lot of ImageButtons where the image aspect does not matter. That is, I do not care if it is stretched. They are invisible buttons to go on top of a background.
Is there an easy way to layout and stretch my ImageButtons through the graphical editor? I do not want to have to test out each possible padding in my xml. I just want to stretch the sides of the images as though it were an Office Word.
Ask if clarification is needed, please.
I'm not really sure to understand your question, but you can use android:scaleType="fitXY" to stretch your images, and android:adjustViewBounds="true" to have them adjust their bounds due to scaling.
I'm not 100% sure about your question neither. If you meant you want to do it in IDE, eclipse allows you to define the button with dragging.
I'm having a trouble here on hot to make my background image fit on a high resolution screen. It works just fine in a 4" screen but image won't stretch out when I deployed it on a larger screen. I tried to search for an answer but nothing helps as of now. well this might be a problem with my xml code but I'm not really sure. My design works with 1 table layout and 2 table rows for the 2 objects. And on the LinearLayout I set my background image.
For further understanding I made a sample on how it looks like when deployed.
There you go. It works fine on my phone while It doesn't occupy the whole space in Galaxy tab. Also as much as possible I would like to make my background image in smaller size around 320x480 pixel is size and just stretch it out.
Set your layout height and width to FILL_PARENT?
Its clear that you did not set Layout_height and Layout_width to fill_parent .
also for better rending put images in all three drawable folders drawable-mdpi, drawable-ldpi,drawable-hdpi .
also make your background image as 9patch will be nice for resizing a backgrond .
Well there are so many reasons I could point out for this problem of yours.
1)First thing the first screen shows a mobile screen and the next one shows a tab avd.
2)The image what u have should be in size to fit a mobile of particular resolutions only.
So your only hope is to get a image with resolution that fits the tab.
Or to change the wrap content to fill parent for your width and height.