First of all I’m new on this forum and this is my first post.
I am am using image as BG of the app and for buttons…but where I am facing problem is like while I have mentioned 60dp margin from top…it is working for current layout but on smaller or larger device it is casing problems like the layout is getting distorted.
Also using .9.png image to avoid px sizing problem.
So can anyone help me with like what should I do to make the layout looks same on every device?
I know on one side its a simple question but on the other end its the most complicated question…
I had the same problem on my last app and solved it by getting the exact dimensions of the screen in pixels, then splitting this dimension into 10 parts. So each part is exactly 10% of the screen in pixels. Then I set the button margins I want with these percentages. So the screen looks the same no matter what size device is being used. You can easily modify this code for your images instead.
Example:
I have a button in a relative layout that needs to be an exact width, height and position on the screen for the app to work right. Margins in dp does not do this for me:
Ok but dont you think that would be too much tiresome to take measurements of the screen or making different xml’s for each size…Im not going against you guys but just asking you…
you can have different layout.xml files , in res/layout folder keep the files for normal screen and in res/layout-sw600dp keep your logic for tablets an so on…
I agree too with @mrBruce. And @coolbud012, yes its tiresome to create different layout for each size… But its much needed if you want to target all devices. Note : there are some techniques to make your layout responsive.