How to Fit Layout on All Screens| Screens Not Working On All Mobiles| How to Fix Landscape Mode




Full tutorial is given below. Dear Viewer we are working hard to maintain this website. We doesn't want any think from you. Its just a humble request If you thinks that this posts helps you please share this post with your friends.






So, first of all use ConstraintLayout in activity to fit all layout on all screens.

Note :  If you want to fit your layout in landscape mode then 
first use ScrollView and then ConstraintLayout like the given example below.


activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


 
    <!-- use Constraint Layout in ScrollView to to 
       keep screen working in landscape mode   -->
    
    
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">



    <ImageView
        android:id="@+id/imageView"
        android:layout_width="115dp"
        android:layout_height="108dp"
        android:layout_marginTop="152dp"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintEnd_toStartOf="@+id/imageView2"
        app:layout_constraintHorizontal_bias="0.31"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="108dp"
        android:layout_height="117dp"
        android:layout_marginEnd="36dp"
        android:layout_marginBottom="36dp"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toTopOf="@+id/imageView3"
        app:layout_constraintEnd_toEndOf="parent" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="111dp"
        android:layout_height="108dp"
        android:layout_marginTop="36dp"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.579"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="337dp"
        android:layout_height="53dp"
        android:text="Use Constraint Layout to Fit Layout on All Screens"
        android:textAlignment="center"
        android:textColor="#E91E63"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/imageView2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="202dp"
        android:layout_height="69dp"
        android:layout_marginTop="36dp"
        android:text="usmtip"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.578"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView3" />


    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>










That's it now run your app test.












Post a Comment

0 Comments