0

I am still somehow new to Android development especially the UI. So my question is about whether What I am doing is right or wrong. Mainly my applications have simple UI but the most important thing is that they must support multiple screen sizes. So I develop all my UIs using pure java not xml because in java I can get the screen size that the application is work on right now and then from this info I can make the buttons and all other elements size and position function of the screen size like:

AnyBtn = new Button(this);
FrameLayout.LayoutParams AnyBtnparams = new FrameLayout.LayoutParams(200 * width / SCREEN_WIDTH, 90 * height / SCREEN_HEIGHT, Gravity.BOTTOM | Gravity.LEFT);
gonczor
4,1841 gold badge25 silver badges53 bronze badges
asked May 24, 2017 at 13:25
1
  • Did you consider using weights? Usually it works pretty well for me and our UIs are quite complicated. Commented May 24, 2017 at 13:52

4 Answers 4

1

https://developer.android.com/training/multiscreen/screensizes.html

Android developer's site has some good information on this topic. Above link might help you.

answered May 24, 2017 at 13:35
Sign up to request clarification or add additional context in comments.

1 Comment

0

Recently I have been through this I need to dimension with different font sizes to support all multiple devices,

But later I found a library which does all these works

just import this library in your gradle, it will allocate the sizes for multiple devices

 compile 'com.intuit.sdp:sdp-android:1.0.3' 

hope this helps :)

answered May 24, 2017 at 13:30

Comments

0

I think thats not a good way to start. Xml was made part of android development because its beats java code in performance.if you look at your apk size, Java code has 80% of the total size. So take your time but learn properly.

answered May 24, 2017 at 13:39

Comments

0

Although making your UI from code isn't a bad idea, code maintenance becomes very difficult.

Luckily, the Android Support Library team has provided us various API's that ensure our UI adapts to all screen densities and sizes.

You can use VectorDrawableCompat and AnimatedVectorDrawableCompat, by creating vectors that scale according to the device. Have a look here.

You could create 9 patch images in Android Studio or an external tool for simpler resources. You could also target different densities with density specific layouts and resources.

PercentRelativeLayout lets you control view dimensions with percentages in XML or Java. ConstraintLayout let's you scale according to the screen's dimensions with scaling ratio control.

answered May 24, 2017 at 13:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.