View issue in Android

You must Login before you can answer or comment on any questions.

i have a general view called view0, inside this i have 3 views view1, view2, view3. the layout in view0 is horizontal, then view1 width is 60% view2 20% and view3 20.

the first issue is view3 when width is 20% is not showed. i had to change width to 15%.

the second issue is in view2 and view3 i have images in vertical layout but when i run the app in emulator and device sometimes the images are diferent sizes or scratched and if i run the app again sometimes in other happens the same!!

Any clue?

1 Answer

Accepted Answer

I know exactly why your first issue happens: if you specify a dimension in percentage, the percentage is taken from the parent view's dimension. If that value is non-integer, it is rounded up.

So for example, if you have a view that is 486 pixels wide, and you have 4 subviews of width='25%', the views will each get a width of 122, which will cause the last view to not be shown. On different devices or emulators, where the screen size is different, you may have views that show on one device but not on another.

As for your second issue, I'm not quite sure I understand it, but I think what your'e describing is also a result of different screen densities and screen sizes. If you have a picture that is 200 pixels wide and you show it on a device with screen density mdpi, it will be physically larger than if you display it on a device with density xhdpi. You have to compensate for these differences in your code, either by specifying different dimensions in pixels for the different densities, or by using density independent pixels.

— answered 9 months ago by Jason Priebe
answer permalink
2 Comments
  • My first question answered, thanks a lot!!! The second now is a problem, i have 3 child views inside a father view. Inside of each view i have in view 1 buttons, view 2 images and view 3 images, the problem is with images, they are icons and everything is fine but for some reason when i run it, aleatory distortionates one icon, every time is different. Kind of weird.

    — commented 9 months ago by Mario Navarro Palos

  • Maybe you should start a new question for that one -- and if you can post a screenshot somewhere along with a minimal code example, that would make it a lot easier to help you.

    — commented 9 months ago by Jason Priebe

Your Answer

Think you can help? Login to answer this question!