Reputation: 113
I have created a demo application in Android using Nexus 9 2048 X 1536
I have added an EditText and assign width as 1000dp it is working fine in Nexus 9 Emulator. But When I change the Emulator as Nexus 5X 1080 X 1920
to test the dp
purpose, Then the EditText goes out of the layout and shown about half of it.
Why it is happening even I assign the width in dp. It should adjust the width by screen-resolution.
Upvotes: 2
Views: 84
Reputation: 5589
You have a few alternatives:
1) The right and recommended one is to make different layouts for different screens. For this alternative see Supporting multiple screens
2) Another alternative I used to use before ConstraintLayout was to make everything proportional. When the app starts I take the meassurement of the Display and layout everything based on that. This is done mostly programatically not using the xml layout file.
3) Use the new ConstraintLayout from the support library. Using this layout you can constraint your widgest relative to each other and or to guidelines you can add to your layout to delimit sections of it. Your widgets that need to adapt will mostly have a width of 0dp or wrap_content and the constraints will take care of resizig them accordingly.
Upvotes: 0
Reputation: 1007544
It should adjust the width by screen-resolution.
No, it does not. dp
will adjust the width by screen density, not screen resolution. You asked for it to be 1000dp wide, and so it will be 1000dp wide, regardless of screen resolution or screen size.
Upvotes: 3