How can I make my ui look the same in different screens?
I made an app and tested it to run on 2 different phones with different screen sizes and it appeared very differently.
Here are some screenshots:
Phone 1: Huawei P20 lite (5.83"):
https://drive.google.com/file/d/1_wa9bcEa46Ygduo47Q8DNTu9-DIhOv5h/view?usp=drivesdk
Phone 2: Samsung Galaxy J1 (4.31"):
https://drive.google.com/file/d/1fNDLea4Vv6LcX-vy-T1S4-XyhHN59pKD/view?usp=drivesdk
How can I make them look the same?
You can achieve this by below Options
Option 1: Make separate layouts file for each device resolution
Option 2: Use Below Library it will automatically support multiple screens.
SDP : https://github.com/intuit/sdp SSP : https://github.com/intuit/ssp
I think you need to spend some more time going through the android documentation specifically focusing on :
DP vs SP - for font size. Understand which one you should use and how font settings (either OS defaults or user overrides) impacts the sizes set for each. Go through this SO discussion - What is the difference between "px", "dip", "dp" and "sp"?
Understand the different layouts available on android and when and how to use them. Spend some time understanding unique attributes for each of them. Have a look at this https://developer.android.com/training/constraint-layout
You should not need any libraries for what you are trying to achieve. The layout seems very straight forward.
Add below into your project level Gradle file:
compile 'com.intuit.sdp:sdp-android:1.0.5'
Usage : In code wherever you are specifying dimensions like 10dp change it to @dimen/_10sdp . Like I have specified in this example ImageView.
<ImageView
android:id="@+id/your_image"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_10sdp"
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"
android:src="@drawable/logo"/>
This will make your application look same on different devices.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.