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
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 always have problems when using images. I want to use an image as splash screen. So I imported all resolutions (ldpi to xxhdpi) of my image using Multisource-Drawable in Android Studio. Then, I created a imageview in my Activity and set Width and Height to 150dp both. It seems to use the ldpi resource and the image get very blurry.
What's the best way to import images in Android Studio to general use?
[UPDATE]
Android is chosing the right size, but not how I want. I fixed it by adding a 512x512 png file and then setting its Width And Height to 150dp
I think your question may have two separate answers. First, you are assuming that an image is the best way to set up a splash screen. This is not so, as the content would have to be called after the app has already finished setting up. That would mean your user sees a flash (or more) of a blank screen before the splash screen is shown. Second, you would like to know the best way to import images into Android Studio. Here are the two different answers:
#1 The best way to implement a splash screen is to have a theme called on a blank activity. The theme would include your desired image and background color. The reason for this is to eliminate the short break before content is called. Click here for a link describing more and giving a tutorial.
#2 In my opinion, the simplest and most robust way to add an image resource is to use the Image Asset import feature. Follow these steps:
Right click on "res" (in the Project View) -> New -> Image Asset
On Icon Type choose Action Bar
and Tab Icons
For Asset Type choose Image
Choose the image path (on your computer)
Give your image a name (no UPPERCASE, only lowercase and underscores, etc)
Next -> Finish
make image view height and width wrap_content and set its gravity to center..
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
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.