layouts designed in sketch software doesnt match when implemented in android - android

I have set a linear layout as 32 dp in sketch app using mac and when the same dimesnsions implemented in android studio and then i took the screen shot and imported to sketch app and when compared with the sketch designed measurements there was a huge difference in the height i.e the height was 44dp so can some help me out in this how to match exact measurements from sketch to android layouts.

I have faced this problem many times and found this solution which worked for me
In sketch first use the art-board which fits material design
for eg: 360 x 640
Get you design fit in height can vary and than try to export your design using zeplin, creat your android project using zeplin and export all your screens, zeplin will help you telling exact font, font size, images size also it allows to copy xml to be used in android studio and this give almost perfect result only difference while comparing is android bottom buttons and screens you need to adjust manually

Related

How to know all the dimens.xml(hYYYdp) files I have to create to support all the screen sizes?

I am a little bit desperate because I'm trying to know how can I know the exact list of different dimens.xml(hYYYdp) I have to create in order to support all the screen sizes. I think I have already seen all the related questions to mine but none of them has helped me to solve this doubt. This is the most related question that hasn't solved my doubt: How to define dimens.xml for every different screen size in android? .
To give you some context. The reason of having different values according to the screen size is because I have a ConstraintLayout with some items that have Top and Bottom margin and in some devices that margin is not looking good. In this post I made, someone suggested me to use different margin values according to the screen size: How to solve TextView being cropped in small devices because of layout margin?
I have thought that as the margin is dependent of the height of the device (as I am using only Top and Bottom margin) I would have to create a list of different dimens.xml files according to the height of the device (hYYYdp).
The real concern I have is that I don't know how many dimens.xml files I have to create to support all the screen sizes. What I have been doing is creating some specific dimens.xml files that are working for specific devices, but I think there has to be a general list of all the dimens.xml files that have to be created to support all the screen sizes.
For example, what I have been doing is to look the test devices of Android Studio one by one and create specific dimens.xml files for them. This is the process I have followed to create a specific dimens file:
Example:
1- First I have seen the list of the test devices of Android Studio, for example let's take this one:
2- After this, I have calculated the dp of the height of this specific test device:
240x400px (ldpi) device. So the height's dp is = 400/(120(ldpi)/160)== 533.33dp
3- Finally, I have added the dimens.xml(hYYYdp) correspondent to this specific device with the specific margin value that is looking good:
I have repeated this process for most of the test devices of Android Studio but as a result, I have a list of specific devices but I think there will remain many devices without being supported as not all the Android devices are in the Android Studio test devices list. I hope you have understand what I am trying to explain.

Kivy TreeView: collapse button really small on android

I'm using TreeView to build an app, and it renders fine when testing on my laptop but the little buttons to collapse/uncollapse tree nodes are tiny on my phone (see the tiny arrow next to Group 1 in the image). I've looked for an attribute or property in TreeView that I could set, but nothing seems to help.
It's probably because using an invalid sizing units. I guess you either used width = 100 or width = 100px or similar thing. Mostly phones and tablets, but even other displays handle such things a little bit differently.
To fix that use dp unit described in the link provided above:
.py:
width = '100dp'
.kv:
#:import dp kivy.metrics.dp
width: dp(100)
To test how the layout looks at such devices use screen module or the commands mentioned in kivy.metrics documentation to manually modify DPI of your application. Screen is more powerful.

Android font size in pt

I'm working on a Android project where I need to build my layouts based on a JSON layout file. This same file is also being used on an iOS app. So there is 1 file which will render the same layout on the Android as well as on the iOS.
The JSON layout file defines its font sizes based on the default iOS font unit.
From the Android docs:
Points - 1/72 of an inch based on the physical size of the screen.
And as far as I can find, iOS font sizes are also defined as 1/72 of an inch.
So based on this info, I'd say the following should be enough:
view.setTextSize(TypedValue.COMPLEX_UNIT_PT, fontSizeInIosUnit)
This however results in the text being too large. And it also seems to differ per device (which is weird since points should always appear in the same physical size).
If you want fonts to resize properly according to screen size you should use dp/dip instead.
So try this instead:
view.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSizeInIosUnit);
Now this might not be exacly the same but in my experience this gives the best results. If it doesn't have the proper size then figure out what size you need on Android as the base size and then go with that instead.

Scale tablet layout to phone

I have a (RelativeLayout) layout xml that was designed to work for 10 inch tablets. I now want the very same layout to be displayed when the app runs on a phone. Instead of it being only displayed partly, I want it to be scaled, so that the structure is the same, just everything a bit smaller.
I have already:
Searched the web - without a result
Read about LayoutInflaters - but have no idea where I could set a scale there
Tried to "override" the defaultWindow's density using Reflection - without a result
Please note that I am aware that this is bad practice, but it's just a personal project and I am curious to know if this is possible.
Any help is highly appreciated!
EDIT: What I want is to really scale the screen as a whole.
I am not the author of the original layout, as it's an open source project for tablets that I want to use on my phone.
Here is the source: https://github.com/amigold/Gui2Go
The layout I am talking about is main.xml.
My reputation is too low to ask you to include a sample layout, and my proposal does not use the exact same layout. However, You can create layouts with the same id tags and filename.xml having the 10 inch tablet version in the folder res/layout-sw600dp and the phone version in res/layout. The layout in /layout-sw600dp will be automatically used for larger screens & the layout in /layout will be used for smaller screens. You will not have to change your setContentView() call at all.
see: http://developer.android.com/guide/practices/screens_support.html

Widgets appear smaller in Eclipse than on the phone

I am currently putting together an application for my HTC Evo 3D phone which has a screen resolution of 960x540. I have set up a custom layout configuration for designing the interface at this resolution. When in this configuration the widgets (texts views, seek bars etc.) appear small and compact, sparse on the screen. Whereas when I launch the application on my phone the buttons are considerably larger and fill the screen more. Is there some setting in Eclipse that will allow me to view the layout in the editor exactly as it would appear on my phone, allowing for easier design of the interface.
Many thanks, Mat.
with relevant code would be easer to help, however, if you are using dp unit measure, sizes will change according to resolution:screensize, not just resolution. I think also a "wrap_content" given to a textview/button etc. would change in size, because font size would be in sp. So, look if there is any emulator configuration that fits real device resolution AND screen size.
Take a look here for more info about measure units.
EDIT
so are you seeing it in eclipse in the graphical layout of yourlayout.xml? on the top bar of that window there's a dropmenu for display configurations, change it to see the layout in different screens (I don't see any 960x540 btw). however, if you really want to develop for one single device is a matter, but if you're going to release the app for different devices, you need some strategy to make flexible layouts. this is very useful.

Categories

Resources