FlyingPumba / SimpleRatingBar

Open source project which features a simple yet powerful RatingBar alternative to Android's default
Apache License 2.0
1.03k stars 142 forks source link

Strange size values #23

Open 2ndGAB opened 7 years ago

2ndGAB commented 7 years ago

Hello, I encounter a strange behavior with app:srb_starSize and app:srb_starsSeparation. I've created a layout with value 42dp for both of these values, displaying 5 stars. That perfectly render on Nexus7 (1920x1080, 7 inches): ratingBar

But it only displays 3 stars on a Galaxy S4 (1920x1080, 5.4 inches). So I wanted to have a look at the star and separation size to see if I have to adapt the values and they are quite surprizing:
On Nexus 7:
ratingBar.getStarSize() = 0.0 ratingBar.getStarsSeparation() = 84.0

On Galaxy S4:
ratingBar.getStarSize() = 0.0 ratingBar.getStarsSeparation() = 126.0

How do you explain these values?

FlyingPumba commented 7 years ago

I don't know why it shows only 3 starts on Galaxy S4.

But the values you have are to be expected. The dp measure unit it's dependent on the ppi (pixel density of the device. Although both devices have the same resolution, they don't have the same ppi. You can see here that Galaxy S4 has 441 ppi, where here that Nexus 7 has 216 ppi. Thus, 42 dp is 126 pixels on Galaxy S4, but 84 pixels on Nexus 7

2ndGAB commented 7 years ago

@FlyingPumba so it explain how the display is not correct I think.

Let's start by the nexus 7. Here is the screen part in full width:
Imgur

The screen is 1080 pixels wide. If the value of 84 pixels for 42 dp is correct then, 5 stars and 4 spaces occupies 84 * 9 = 756 pixels, which seems to be quite logical regarding the screenshot.

Now let's consider the Galaxy S4 case: Imgur

The screen is also 1080 pixels wide.If the value of 126 pixels for 42 dp is correct then, 5 stars and 4 spaces occupies 126* 9 = 1134 pixels, which explains why the 7 stars cannot be displayed.

So I think there is something wrong somewhere.

I think that for 2 devices with the same screen resolution, the size in pixels should be the same no?

Or there is something I didn't undestand.

And why getStarSize() returns 0?

I think it would be very intersting to have a fill option for srb_gravity, which calculates automatically srb_starsSeparation to fill the available space.

FlyingPumba commented 7 years ago

@2ndGAB getStarSize() shouldn't return 0, that's weird. The problem here is that I can't reproduce this behaviour, since I don't have a Galaxy S4 or a Nexus 7. If you can provide a sample project I'll try to reproduce it on my phone.

I think it would be very intersting to have a fill option for srb_gravity, which calculates automatically srb_starsSeparation to fill the available space.

srb_gravity is not meant for that, it only changes the direction of the fill. Nevertheless, the behaviour you describe is the default behaviour when the user doesn't provide star separation.

Perhaps the problem is related to the fact that you are using the rating bar on a dialog, have you tried a normal layout to see what happens ?

2ndGAB commented 7 years ago

Nevertheless, the behaviour you describe is the default behaviour when the user doesn't provide star separation.

! ? ! There is a big problem here because it's not the default behavior I see.

here is the sample test project.

FlyingPumba commented 7 years ago

@2ndGAB I'll look into the example project. and let you know if I find anything.