0

have designed my layout to match and fit all the designs in xml but unfortunately am experiencing the un balanced layout of course i know using raw figures is not advices now how can i achieve this layout to match all my screen devices using xml.

This is the layout i want to achieve in  all my android devices

""Here is my code snippet but that does not match all devices especially with bigger screens""

<?xml version="1.0" encoding="utf-8"?>
<!--Home Fragment layout-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

 <LinearLayout
     android:id="@+id/layoutonescholarship"
     android:background="@drawable/home_box"
     android:layout_width="match_parent"
     android:layout_height="200dp">

     <TextView
         android:id="@+id/text1"
         android:layout_marginLeft="20dp"
         android:textSize="35sp"
         android:layout_marginTop="40dp"
         android:text="@string/scholarshiptoday"
         android:fontFamily="sans-serif-black"
         android:textColor="@color/colorAccent"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>


      <TextView
          android:layout_marginLeft="-280dp"
          android:layout_marginTop="65dp"
          android:textColor="@color/colorAccent"
          android:fontFamily="sans-serif"
          android:text="@string/seescholarship"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>


 </LinearLayout>

    <LinearLayout
        android:layout_marginTop="110dp"
        android:id="@+id/scholarhip"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:orientation="vertical">


        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:orientation="horizontal"
            tools:listitem="@layout/scholarship_item_card_"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            android:id="@+id/recyclerViewscholarship"
            android:layout_height="match_parent"/>


    </LinearLayout>

  <LinearLayout
      android:layout_marginTop="10dp"
      android:layout_below="@id/scholarhip"
      android:id="@+id/jobsandinterns"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal">

      <TextView
          android:layout_marginLeft="15dp"
          android:textColor="@color/colorPrimary"
          android:textSize="25sp"
          android:fontFamily="sans-serif-black"
          android:id="@+id/jobsandinternstitle"
          android:layout_width="wrap_content"
          android:text="@string/jobsandinterns"
          android:layout_height="wrap_content"/>

  </LinearLayout>

    <LinearLayout
        android:id="@+id/browsetitle"
        android:layout_below="@id/jobsandinterns"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:textSize="12sp"
            android:textColor="@color/colorPrimary"
            android:layout_marginLeft="19dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/browse"/>

    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="5dp"
        android:id="@+id/jobsandinternsbannerimage"
        android:layout_below="@id/browsetitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:orientation="horizontal"
            tools:listitem="@layout/jobsandintern_tem"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            android:id="@+id/recyclerViewjobsandinterns"
            android:layout_height="match_parent"/>

    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="5dp"
        android:layout_below="@id/jobsandinternsbannerimage"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_gravity="center"
            android:src="@drawable/banner2020"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </LinearLayout>



</RelativeLayout>
Kyle Mutta
  • 379
  • 1
  • 5
  • 16

1 Answers1

0

You have to create separate xml files for each screen size. Here's how you can do it:

  1. Go to res/layout
  2. Right-click on layout. Go to New and then New Layout Resource File.
  3. Then, you will receive a pop-up for the new resource file. In the File Name: box make sure to have the exact same name as the xml file you wish to match a certain screen size.
  4. The in the available qualifiers, look for size and choose it. Then, you will see a drop-down menu for the screen-size and you can choose your required screen size there.
  5. Another qualifier you need is the Orientation qualifier. Choose it and then select the orientation you need from the drop-down menu.
Mahir Islam
  • 1,941
  • 2
  • 12
  • 33