How to resize icon automatically upon adding new icon? - android

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.

Related

Android App - Aligning EditTexts doesn't work

I'm writing my first Android-App. The App should solve Sudokus for the user.
So the interface should look like the typical Sudoku-Layout with some Buttons down below. For the number-fields i just used EditTexts.
At first i used a ContrainsLayout. That worked fine so far but the problem is that the editTexts on the right are not visible anymore if the screen of the user is too small.
I use a fixed height and width of 40dp for the editTexts and a constraint of 1dp between the editTexts.
But i cant get it to work that way on different screen sizes.
So i used the GridLayout. There problem here is that i cant get the whole thing to be in the center. And besides that i dont know if its possible to stretch a TEXTview over multiple rows?! I would need this to show the errorText in case the sudoku isnt solvable.
I hope someone can help me out or at least give me some ideas :)
Thanks in advance
If you want the same result for different screen sizes the recommendation is constraint layout but the reason you don't have the same result is that you used hard coded width and height and on different sizes you need to change the size that you hard coded.
The best thing to do is to make separate xml files for screen sizes
for more info you can see here: how to have different sizes supported

Background image appear to be small in android app?

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

Button.getMeasureWidth() returns bigger value than actual size. / Make very small buttons programatically

I got stuck with these problems :
I have a button . I want to make it (programatically) as small as I want ( e.g. width = 1, height = 1). I tried with setWidth(1) and setHeight(1) but it doesn't work . I searched and I found something about small buttons. So i created my button like:
Button b1 = new Button(mContext,null,android.R.attr.buttonStyleSmall);
b1.setMinimumHeight(0);
b1.setMinimumWidth(0);
b1.setWidth(1);
b1.setHeight(1);
The buttons got smaller , but not small enough . They still seem to have a min size bigger than (0,0) . I could set at every size i wanted by using params, but I don't understand why it's not working without using params.Please give me a solution or just explain me why it's only working this way.
I need to make the text inside a button to fit the space. (i want the text to be as bigger as possible). I had to do a similar job for a textView . The solution I found was to do a binary search for the size of the font (initially i set the maxWidth, textView.setMaxWidth(maxWidth)) and then use textView.measure(MeasureSpec.Unspecified,MeasureSpec.Unspecified) and use getHeightMeasurement to check if it fits the maxHeight. This solution worked for the TextView, but not for the button.
That is because whatever i do , the button.getHeightMeasurement() returns a bigger value than what i wanted ( this happens even when the text inside the button is "" and the font size is 0). So please help me. Ask me for pieces of code or clarification . It's very annoying.
Thanks and sorry for my bad english.

How to have images go to the next line if they dont fit

I am using Linear layout with horizontal orientation to put images beside each other. However, is there way that the images can automatically go to the next line incase they dont fit due to screen size?
I just dont want small screen (or small densities) to truncate my images
Thank you
Use RelativeLayout and reorder images via code according to image sizes and space.
OR
Extend GridLayout and make your own implementation of it.
This is not possible in LinearLayout as it is.

Fit Image on an android screen

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.

Categories

Resources