I am working on a project and I can't figure it out after long time searching, how to manage and fit my layout to every screen size. I tried everything and it just split the objects on the screen. I need to create a stable layout that doesn't change through the different screen sizes. I will appreciate your help.
-
The question is too generic. You can start from this and read further: https://developer.android.com/guide/practices/screens_support.html – XH6 user Nov 14 '17 at 19:50
2 Answers
If you want a layout that shows correctly across various screen sizes, try not to hard code positions of the objects inside the layout. For example, don't use android:layout_marginLeft="50dp"
and|or android:paddingLeft="50dp"
, etc to position the object inside the layout.
Instead, use more of
android:layout_weight
and android:layout_gravity
in LinearLayout
and
android:layout_centerInParent
, android:layout_centerHorizontal
or android:layout_centerVertical
in RelativeLayout.
Make sure the parent layout has:
android:layout_height="match_parent"
android:layout_width="match_parent"

- 71
- 4
In Constraint layout,you can use the Chaining feature ConstraintLayout Chains to spread views across the screen. In addition to that you have the option to specify 0 width and height, and manage the width and height with the constraint ratio feature Constraint layout ratio so that your User Interface becomes dynamic with respect to screen size. You can refer the full documentation here and here.

- 658
- 1
- 11
- 27