Its odd and I don’t know why that happens but if you use a regular vertical arrangement and set it to IsCard it makes it a square. Hopefully someone actually solves this for you though.
It doesn’t have options to adjust corner radius, padding, elevation etc. na ?
Not sure. Maybe there are extensions.
I created a new project & tried the very same blocks. But the height & width are never equal (Height is always greater than width). Is this some kind of bug ???
What happens if you set the size with direct numbers instead of a calculation?
Have you tried making the calculation before the height and width blocks into a variable and use that variable instead?
Yes… I tried storing the screen width value to a variable. But still the same result.
Not the screen width. I said the result of the calculation.
My point is: Even if I try to make a square like this, the result is still a rectangle.
If you don’t mind, could you please check if you can make a 57px square within Kodular ?
This is the result I get within companion & I’m sure that this isn’t a square.
I hope now others will also understand my point. It’s way more noticeable when the size is small
From the documentation of Android Developer Platform:
Since padding is used to offset content for shadows, you cannot set padding on CardView. Instead, you can use content padding attributes in XML or
setContentPadding(int, int, int, int)
in code to set the padding between the edges of the CardView and children of CardView.
Before Lollipop, CardView adds padding to its content and draws shadows to that area. This padding amount is equal to
maxCardElevation + (1 - cos45) * cornerRadius
on the sides andmaxCardElevation * 1.5 + (1 - cos45) * cornerRadius
on top and bottom.
As u can see you don’t have the possibility to manipulate maxCardElevation parameter.
It’s probably hard to answer the question, because in kodular we don’t have full acces to every possible parameter of classes. It seems like cardview View makes some background calculations for the border and shadows and depending on the android version it works differently. Maybe that’s the reason. For example this:
https://developer.android.com/reference/androidx/cardview/widget/CardView#setPreventCornerOverlap(boolean)
I dont know what happened, but i got an idea.
try finding the proportion of the rectangle, and use that in the blocks.
Also, maybe your phone has got rectangular pixels?
I have done some testing and the difference in height and width for me seems to be 6px. So when I set the width to (screen width * 0.16) I set the height to (screen width * 0.16) - 6.
This works for any size (for me, hopefully same for you)
The way I tested is: Put a vertical arrangement inside a card view and set its height and width to fill parent. Then you can see the actual size of the card view by checking the dimensions of the vertical arrangement.
If you place the Card View within a HA then what exactly is the point of using one ? We use it cause we can control the properties like corner radius, padding, elevation etc.
Try by setting your Card Elevation to 8
So a square or rectangle must have a width of at least 17px in order to be displayed at all by a CardView.