问题
I'm working on an android App,and it's designed with numbers (margins etc) no relative things so I think I'll find many problems with different screen sizes so I thought of making a function which will keep the data in DIMENSIONS
file proportional to user screen size like ( User's screen size X dimen)/(the screen size which the app were designed on)
, so I want to know if this won't cause any problem on App working etc ..
Thank you =)
回答1:
Create three different Layouts Folder
in your res
folder for all devices and use the dimensions accordingly.
Generic Layout Folders
res/layout-small
res/layout-normal
res/layout-large
res/layout-xlarge
After you are done with making your Normal/Medium Layouts follow these steps:
- Convert the Normal Dimensions for other Screen Sizes.
- Copy your Normal Layout xml files in to other Folders.
- Change the suffix of the dimensions used according to the folder that you are in
- Resize the Image Resources in your drawable folder (Width and Height - Same technique as we used for converting the dimens) and put them in their respective drawable folder (drawable-ldpi, drawable-mdpi, drawable-hdpi, drawable-xdpi and so on).
- Then your Layouts should work on every device with correct positioning.
For converting Values
0.75 - ldpi (small) //mdpi dimens *0.75
1.0 - mdpi (normal) //First create these dimensions
1.5 - hdpi (large) //mdpi dimens *1.5
2.0 - xhdpi (xLarge) //mdpi dimens *2.0
For Example
android:layout_width="66dip" //in normal
android:layout_width="100dip"//in large 66*1.5=100(approx)
android:layout_width="52dip" //in small 66*0.75=52(approx)
Also new Qualifier has been introduced - SmallestWidth - AvailableScreenWidth - AvailableScreenHeight
read more about it here https://developer.android.com/guide/practices/screens_support.html
I hope this helps.
回答2:
May be you can try below library which manages all the screen size resolution automatically.
compile 'com.intuit.sdp:sdp-android:1.0.4'
You need to just add the dependency in your build.gradle
file and you are done.
You need to specify like:
android:layout_height="@dimen/_10sdp"
Instead of:
android:layout_height="@dimen/10sdp"
回答3:
//Dimen
implementation 'com.intuit.ssp:ssp-android:1.0.5'
implementation 'com.intuit.sdp:sdp-android:1.0.5'
use this two library, ssp is for text size, and sdp is for margin, padding and layout size
android:layout_width="@dimen/_24sdp"
android:layout_height="@dimen/_24sdp"
来源:https://stackoverflow.com/questions/41498646/handling-all-screen-sizes-android