Adding an image to a constraint layout using JAVA - java

i am experiencing some problems when I try to add an image to my contraint layout. I have the next CL:
I add also the xml code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".pl.view.activities.Test1Activity"
android:id="#+id/test_layout">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:fontFamily="sans-serif-black"
android:text="1. Galdera: bla bla bla..."
android:textColor="#1E0354"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:text="1. aukera"
app:layout_constraintBottom_toTopOf="#+id/radioButton2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:text="2. aukera"
app:layout_constraintBottom_toTopOf="#+id/radioButton3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioButton" />
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:text="3. aukera"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioButton2" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="128dp"
android:background="#drawable/button_rounded"
android:text="CHECK"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioButton3" />
<Button
android:id="#+id/next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="34dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:background="#drawable/button_rounded"
android:text="Next"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button3" />
</androidx.constraintlayout.widget.ConstraintLayout>
I want to place a image, but just sometimes, between the title of the question, the element which is in the top, and the first radioButton.
I have seen a lot of ways to do it but none of them is working.
Thanks for support!

If I were you I would add the image to the XML and make its visibility GONE, then when needed would change to VISIBLE.

Related

Android studio AVD glitch

I am new to android studio. Literally its my first day on the software. I am having issue with AVD Screen
I have used the default pixel 3 avd to run the apk but here is the problem:-
SO here is the
Output and here is the
Input
. I am sorry if it has any silly mistake but please help me it will make my day ❤
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#454545"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="385dp"
android:layout_height="41dp"
android:layout_marginTop="16dp"
android:fontFamily="#font/black_ops_one"
android:shadowColor="#70000000"
android:shadowDx="10"
android:shadowDy="5"
android:shadowRadius="1"
android:text=" Sumant Dusane"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:textColor="#FFFFFF"
android:textSize="25sp"
android:textStyle="bold"
android:translationZ="5dp"
android:typeface="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="295dp"
android:layout_height="0dp"
android:layout_marginStart="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:layout_marginBottom="435dp"
android:alpha="0.2"
android:background="#FFFFFF"
android:scaleX="15"
android:translationZ="4dp"
app:layout_constraintBottom_toTopOf="#+id/imageView5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/textView"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/marble_texture" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="447dp"
android:layout_height="799dp"
android:alpha="0.5"
android:scaleY="1.9"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.25"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="#drawable/matte_painitng_corrected__main" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="41dp"
android:layout_marginLeft="41dp"
android:layout_marginEnd="29dp"
android:layout_marginRight="29dp"
android:layout_marginBottom="18dp"
app:layout_constraintBottom_toTopOf="#+id/imageView6"
app:layout_constraintEnd_toStartOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView3"
app:srcCompat="#drawable/instagram" />
<TextView
android:id="#+id/textView4"
android:layout_width="219dp"
android:layout_height="42dp"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:fontFamily="#font/frank_ruhl_libre_medium"
android:text="#s.u.m.a.n.t_8282"
android:textColor="#FFFFFF"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="#+id/imageView5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView5"
app:layout_constraintTop_toTopOf="#+id/imageView5" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="49dp"
android:layout_marginLeft="49dp"
android:layout_marginEnd="29dp"
android:layout_marginRight="29dp"
android:layout_marginBottom="57dp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
app:layout_constraintEnd_toStartOf="#+id/textView5"
app:layout_constraintHorizontal_bias="0.52"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView5"
app:srcCompat="#drawable/linkedin" />
<TextView
android:id="#+id/textView5"
android:layout_width="210dp"
android:layout_height="31dp"
android:layout_marginEnd="26dp"
android:layout_marginRight="26dp"
android:fontFamily="#font/frank_ruhl_libre_medium"
android:lineSpacingExtra="5sp"
android:text="Sumant Dusane"
android:textColor="#FFFFFF"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="#+id/imageView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView6"
app:layout_constraintTop_toTopOf="#+id/imageView6" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="106dp"
android:text="Follow for more !!"
android:textColor="#FFFFFF"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView6" />
</android.support.constraint.ConstraintLayout>

Constraint Layout not working; the layout is destroyed across devices

Desired Layout Photo
Current Layout Photo when tested
Across different devices the layout changes drastically. I have looked around on google for answers but nothing has provided clarity between what is the right way to do things and what is not. What can be done?
Note: There are twenty identical copies of the last image view that are not included in the code below. They are meant to be moved around for graphics.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.example.castbuddyv1.FFVisuals
android:id="#+id/FFVisuals"
android:layout_width="389dp"
android:layout_height="781dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rawdata" />
<Button
android:id="#+id/right2"
android:layout_width="59dp"
android:layout_height="48dp"
android:layout_marginStart="84dp"
android:layout_marginLeft="84dp"
android:layout_marginTop="658dp"
android:layout_marginBottom="29dp"
app:icon="#drawable/abc_vector_test"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/onoff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.39" />
<ToggleButton
android:id="#+id/onoff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="700dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:rotation="0"
android:textOff="Motors On"
android:textOn="Motors Off"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.922" />
<Button
android:id="#+id/right"
android:layout_width="59dp"
android:layout_height="48dp"
android:layout_marginTop="658dp"
android:layout_marginEnd="51dp"
android:layout_marginRight="51dp"
android:layout_marginBottom="29dp"
android:rotation="180"
app:icon="#drawable/abc_vector_test"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/onoff"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="#+id/statusdisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="166dp"
android:layout_marginLeft="166dp"
android:layout_marginTop="595dp"
android:layout_marginEnd="183dp"
android:layout_marginRight="183dp"
android:layout_marginBottom="44dp"
android:text="Status:"
app:layout_constraintBottom_toTopOf="#+id/onoff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/depth"
android:layout_width="80dp"
android:layout_height="31dp"
android:layout_marginEnd="49dp"
android:layout_marginRight="49dp"
android:text="Depth:"
app:layout_constraintBottom_toBottomOf="#+id/rawdata"
app:layout_constraintEnd_toStartOf="#+id/connect"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/connect"
app:layout_constraintVertical_bias="1.0" />
<Switch
android:id="#+id/rawdata"
android:layout_width="92dp"
android:layout_height="34dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="692dp"
android:text="Raw Data"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/connect"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/connect"
android:layout_width="110dp"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="#string/connect"
app:layout_constraintBottom_toBottomOf="#+id/rawdata"
app:layout_constraintEnd_toStartOf="#+id/rawdata"
app:layout_constraintStart_toEndOf="#+id/depth"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<ImageView
android:id="#+id/fish"
android:layout_width="57dp"
android:layout_height="33dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="320dp"
android:layout_marginRight="320dp"
android:layout_marginBottom="87dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/kisspng_computer_icons_symbol_clip_art_5b2bf54c62bee1_4646889015296075004045
</androidx.constraintlayout.widget.ConstraintLayout>
I'm not sure what is this part :
<com.example.castbuddyv1.FFVisuals
android:id="#+id/FFVisuals"
android:layout_width="389dp"
android:layout_height="781dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rawdata" />
I'm a beginner, I don't know if this is going to help you, but let's say I want to design your interface, for me I will do this:
Making sure to display the interface in vertical by adding below code to AndroidManifest.xml file:
android:screenOrientation="sensorPortrait"
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Putting vertical and horizontal guidelines in the constraintlayout:
<androidx.constraintlayout.widget.Guideline
android:id="#+id/v_guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/h_guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp" />
Replacing (app:layout_constraintGuide_begin="20dp") with (app:layout_constraintGuide_percent="x%") to place it depending on the percentage.
For example : 30% for the first vertical guideline and 50% for the first
horizontal guidline :
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.3" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/h_guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
This is what I do to make sure that each widget appears in the position I want.
Here how it's look in Android studio:
Design+Blueprint
this is how it looks in : Pixel XL 1440 × 2560: 560dpi:
Pixel XL
this is how it looks in: Nexus 9 2048×1536:xhdpi24:
Nexus 9
you can see that the screen size changed but the widgets stay in the same position
this is the xml for this interface:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/h_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.03" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/h_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.1" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/h_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.8" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/h_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.9" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/h_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.97" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/v_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.2" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/v_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.35" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/v_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.65" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/v_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.8" />
<TextView
android:id="#+id/depth"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Depth:"
app:layout_constraintTop_toTopOf="#+id/h_0"
app:layout_constraintBottom_toTopOf="#+id/h_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#+id/v_0"
/>
<Button
android:id="#+id/connect"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="#string/connect"
app:layout_constraintTop_toTopOf="#+id/h_0"
app:layout_constraintBottom_toTopOf="#+id/h_1"
app:layout_constraintStart_toEndOf="#+id/v_1"
app:layout_constraintEnd_toStartOf="#+id/v_2"
/>
<Switch
android:id="#+id/rawdata"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Raw Data"
app:layout_constraintTop_toTopOf="#+id/h_0"
app:layout_constraintBottom_toTopOf="#+id/h_1"
app:layout_constraintStart_toEndOf="#+id/v_3"
app:layout_constraintEnd_toEndOf="parent"
/>
<Button
android:id="#+id/right2"
android:layout_width="0dp"
android:layout_height="0dp"
app:icon="#drawable/abc_vector_test"
app:layout_constraintTop_toBottomOf="#+id/h_3"
app:layout_constraintBottom_toTopOf="#+id/h_4"
app:layout_constraintStart_toStartOf="#+id/v_0"
app:layout_constraintEnd_toStartOf="#+id/v_1"
/>
<ToggleButton
android:id="#+id/onoff"
android:layout_width="0dp"
android:layout_height="0dp"
android:rotation="0"
android:textOff="Motors On"
android:textOn="Motors Off"
app:layout_constraintTop_toBottomOf="#+id/h_3"
app:layout_constraintBottom_toTopOf="#+id/h_4"
app:layout_constraintStart_toEndOf="#+id/v_1"
app:layout_constraintEnd_toStartOf="#+id/v_2"
/>
<Button
android:id="#+id/right"
android:layout_width="0dp"
android:layout_height="0dp"
android:rotation="180"
app:icon="#drawable/abc_vector_test"
app:layout_constraintTop_toBottomOf="#+id/h_3"
app:layout_constraintBottom_toTopOf="#+id/h_4"
app:layout_constraintStart_toEndOf="#+id/v_2"
app:layout_constraintEnd_toStartOf="#+id/v_3"
/>
<TextView
android:id="#+id/statusdisplay"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Status:"
app:layout_constraintTop_toTopOf="#+id/h_2"
app:layout_constraintStart_toStartOf="#+id/v_1"
app:layout_constraintEnd_toStartOf="#+id/v_2"
/>
<ImageView
android:id="#+id/fish"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="#+id/h_2"
app:layout_constraintBottom_toTopOf="#+id/h_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#+id/v_0"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
notice that I set the width and height of the widgets to 0dp:
android:layout_width="0dp"
android:layout_height="0dp"
Since the guidelines are set in a percentage, the widgets will be stretch and Shrink according to the size of the screen
you can make the widgets size-fixed by assign dp values for example:
android:layout_width="70dp"
android:layout_height="40dp"
that all what I got, I hope my explanation is clear and useful.
You can learn ConstrainLayout from here
I've try to figure it out the issue with constraint applied in your code. I hope this will help you, please check this code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<com.example.castbuddyv1.FFVisuals
android:id="#+id/FFVisuals"
android:layout_width="389dp"
android:layout_height="781dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rawdata" />
<Button
android:id="#+id/right2"
android:layout_width="59dp"
android:layout_height="48dp"
android:layout_marginBottom="29dp"
app:icon="#drawable/abc_vector_test"
app:layout_constraintBaseline_toBaselineOf="#id/onoff"
app:layout_constraintEnd_toStartOf="#+id/onoff" />
<ToggleButton
android:id="#+id/onoff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:rotation="0"
android:textOff="Motors On"
android:textOn="Motors Off"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/right"
android:layout_width="59dp"
android:layout_height="48dp"
android:layout_marginBottom="29dp"
android:rotation="180"
app:icon="#drawable/abc_vector_test"
app:layout_constraintBaseline_toBaselineOf="#id/onoff"
app:layout_constraintStart_toEndOf="#+id/onoff" />
<TextView
android:id="#+id/statusdisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="44dp"
android:text="Status:"
app:layout_constraintBottom_toTopOf="#+id/onoff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/depth"
android:layout_width="80dp"
android:layout_height="31dp"
android:layout_marginStart="16dp"
android:text="Depth:"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/connect" />
<Switch
android:id="#+id/rawdata"
android:layout_width="92dp"
android:layout_height="34dp"
android:layout_marginEnd="16dp"
android:text="Raw Data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/connect"
android:layout_width="110dp"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="Connect"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/fish"
android:layout_width="57dp"
android:layout_height="33dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="87dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#mipmap/ic_launcher" />
</androidx.constraintlayout.widget.ConstraintLayout>

My app looking weird in small sized screen

I am an android studio beginner, and here is an app I made.
How it looks in the IDE:
How it looks on my Tablet (9 inch screen):
And how it looks on my Mom's phone (6 inch screen):
As you can see, the objects are getting squished to the bottom of the screen in the case of Mom's phone, whose screen is significantly smaller than my Tablet. I used Constraint Layout to make this app. I don't understand why this happens.
I'd be pleased to give any more information if required.
Edit: Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="#+id/textview_number_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:hint="Enter first fraction"
android:inputType="number|text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<EditText
android:id="#+id/textview_number_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:hint="Enter second fraction"
android:inputType="number|text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview_number_1" />
<Button
android:id="#+id/button_add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:text="Add"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview_number_2" />
<TextView
android:id="#+id/textView_result"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="0"
android:textColor="#323232"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<Switch
android:id="#+id/switch_simplify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Simplify result "
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button_divide" />
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"
android:gravity="center"
android:text="Fractions Calculator"
android:textColor="#673AB7"
android:textSize="30sp"
android:textStyle="bold|italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button_subtract"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="Subtract"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button_add" />
<Button
android:id="#+id/button_multiply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="Multiply"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button_subtract" />
<Button
android:id="#+id/button_divide"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="Divide"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button_multiply" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:text="Result:"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/switch_simplify" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center"
android:text="This calculator only calculates fractions, and does not calculate whole numbers. Please enter the numbers only in the form a/b"
android:textColor="#323232"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_result" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:text="DK Apps"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Build v1.0.0"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Your mom's phone has a small screen so you should wrap your content in a ScrollView in order for all of it do be displayed.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Why does Gridlayout move view out of sight at a certain point

I played around with GridView in Android a bit and there was something strange I noticed, that I could not explain.
In my XML I have an ImageView and underneath a GridView with 4 buttons:
https://s17.directupload.net/images/191020/kho7sds4.png
The code of the XML looks like this:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="550dp"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
<androidx.gridlayout.widget.GridLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:columnCount="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:rowCount="4">
<Button
android:id="#+id/buttonChoice1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="fill"
android:text="Button"
android:textAlignment="center"
app:layout_column="0"
app:layout_columnWeight="1"
app:layout_row="0"
app:layout_rowWeight="1" />
<Button
android:id="#+id/buttonChoice2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="fill"
android:text="Button"
android:textAlignment="center"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_column="0"
app:layout_row="1"/>
<Button
android:id="#+id/buttonChoice3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="fill"
android:text="Button"
android:textAlignment="center"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_column="0"
app:layout_row="2"/>
<Button
android:id="#+id/buttonChoice4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="fill"
android:text="Button"
android:textAlignment="center"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_column="0"
app:layout_row="3"/>
</androidx.gridlayout.widget.GridLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Now when I increase the size of the picture (height:550dp), it looks like this:
https://s17.directupload.net/images/191020/qarbb8g8.png
I guess that the buttons don't have place anymore to display their text correctly, but why would Android then display the GridLayout that way? Is there any way to make this View "failsafe"?
I came up with this solution.You should change the button height property to zero then they would be scale to fit into your grid view.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="550dp"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_foreground" />
<androidx.gridlayout.widget.GridLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:columnCount="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:rowCount="4">
<Button
android:id="#+id/buttonChoice1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="fill"
android:text="Button"
android:textAlignment="center"
app:layout_column="0"
app:layout_columnWeight="1"
app:layout_row="0"
app:layout_rowWeight="1" />
<Button
android:id="#+id/buttonChoice2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="fill"
android:text="Button"
android:textAlignment="center"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_column="0"
app:layout_row="1"/>
<Button
android:id="#+id/buttonChoice3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="fill"
android:text="Button"
android:textAlignment="center"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_column="0"
app:layout_row="2"/>
<Button
android:id="#+id/buttonChoice4"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="fill"
android:text="Button"
android:textAlignment="center"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:layout_column="0"
app:layout_row="3"/>
</androidx.gridlayout.widget.GridLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

My items are all messed up when I run the app on my phone

When I design the app in android studio everything is where it belongs. Why when I view it on my phone everything is messed up?
Studio
On phone
I use Constraint layout. I tried changing API version to an older one, but nothing happened. Does it have something to do with resolutions? I can't use emulators I need it on my phone.
Activity XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="393dp"
android:layout_height="76dp"
android:layout_marginEnd="16dp"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<Button
android:id="#+id/button8"
android:layout_width="65dp"
android:layout_height="55dp"
android:layout_marginTop="348dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:text="#string/button_open"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<Button
android:id="#+id/button9"
android:layout_width="65dp"
android:layout_height="55dp"
android:layout_marginTop="412dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:text="#string/button_open"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<View
android:id="#+id/view9"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="184dp"
android:background="#android:color/darker_gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<View
android:id="#+id/view8"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="480dp"
android:background="#android:color/darker_gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<View
android:id="#+id/view4"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="408dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:background="#android:color/darker_gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<View
android:id="#+id/view6"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="260dp"
android:background="#android:color/darker_gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<View
android:id="#+id/view7"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="336dp"
android:background="#android:color/darker_gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<View
android:id="#+id/view5"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="104dp"
android:background="#android:color/darker_gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView30"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_marginTop="448dp"
android:layout_marginEnd="244dp"
android:layout_marginRight="244dp"
android:text="#string/inbox_text6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView29"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_marginTop="156dp"
android:layout_marginEnd="188dp"
android:layout_marginRight="188dp"
android:text="#string/inbox_text2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView28"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_marginTop="376dp"
android:layout_marginEnd="244dp"
android:layout_marginRight="244dp"
android:text="#string/inbox_text5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView22"
android:layout_width="75dp"
android:layout_height="27dp"
android:layout_marginTop="352dp"
android:layout_marginEnd="324dp"
android:layout_marginRight="324dp"
android:text="#string/inbox_title5"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView23"
android:layout_width="75dp"
android:layout_height="27dp"
android:layout_marginTop="416dp"
android:layout_marginEnd="324dp"
android:layout_marginRight="324dp"
android:text="#string/inbox_title6"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView18"
android:layout_width="75dp"
android:layout_height="27dp"
android:layout_marginTop="272dp"
android:layout_marginEnd="324dp"
android:layout_marginRight="324dp"
android:text="#string/inbox_title4"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView19"
android:layout_width="173dp"
android:layout_height="34dp"
android:layout_marginTop="120dp"
android:layout_marginEnd="228dp"
android:layout_marginRight="228dp"
android:text="#string/inbox_title2"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView20"
android:layout_width="75dp"
android:layout_height="27dp"
android:layout_marginTop="208dp"
android:layout_marginEnd="324dp"
android:layout_marginRight="324dp"
android:text="#string/inbox_title3"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView21"
android:layout_width="137dp"
android:layout_height="30dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="264dp"
android:layout_marginRight="264dp"
android:text="#string/inbox_title1"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView24"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_marginTop="300dp"
android:layout_marginEnd="256dp"
android:layout_marginRight="256dp"
android:text="#string/inbox_text4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView27"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_marginTop="232dp"
android:layout_marginEnd="260dp"
android:layout_marginRight="260dp"
android:text="#string/inbox_text3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<TextView
android:id="#+id/textView26"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="216dp"
android:layout_marginRight="216dp"
android:text="#string/inbox_text1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<Button
android:id="#+id/button5"
android:layout_width="65dp"
android:layout_height="55dp"
android:layout_marginTop="196dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:text="#string/button_open"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<Button
android:id="#+id/button6"
android:layout_width="65dp"
android:layout_height="55dp"
android:layout_marginTop="268dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:text="#string/button_open"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="4">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search" />
<Button
android:layout_width="52dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Refresh" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="goToAnActivity"
android:text="Send" />
</LinearLayout>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
In Android, you need to consider the number of different screen sizes when developing an android application.
Different phones got different screen size, in your layout you are using fixed size on your view (fixed size is 50dp for example) and the result is that what may look good on one screen (your android studio preview screen) will not look good on another screen (your actual phone).
So what can you do to support different screen sizes?
You can fix this by creating a single layout for every screen size but that's a lot of work.
You can also define Relative Layout with android:weightSum and layout_weight
But there is an even better option:
Use ConstraintLayout with guidelines and Chains to support different screen sizes.
From the documentation:
The best way to create a responsive layout for different screen sizes is to use ConstraintLayout as the base layout in your UI. ConstraintLayout allows you to specify the position and size for each view according to spatial relationships with other views in the layout. This way, all the views can move and stretch together as the screen size changes.
And here is an example of a similar layout like you want to achieve:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline7" />
<TextView
android:id="#+id/textView4"
android:layout_width="62dp"
android:layout_height="19dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView9"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView10"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView11"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView9" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView12"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView10" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView13"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView11" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView14"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView12" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView15"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView13" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView16"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView14" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView18"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView15" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/guideline6"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView18" />
<TextView
android:id="#+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/textView17"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView16" />
<android.support.constraint.Guideline
android:id="#+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.8" />
<android.support.constraint.Guideline
android:id="#+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.1" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/button10"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline6" />
<Button
android:id="#+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rfreshe"
app:layout_constraintBottom_toBottomOf="#+id/button9"
app:layout_constraintEnd_toStartOf="#+id/button11"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/button9"
app:layout_constraintTop_toTopOf="#+id/button9" />
<Button
android:id="#+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"
app:layout_constraintBottom_toBottomOf="#+id/button10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/button10"
app:layout_constraintTop_toTopOf="#+id/button10" />
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="open"
app:layout_constraintBottom_toBottomOf="#+id/textView17"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/textView18" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="open"
app:layout_constraintBottom_toBottomOf="#+id/textView16"
app:layout_constraintEnd_toEndOf="#+id/button12"
app:layout_constraintTop_toTopOf="#+id/textView15" />
<Button
android:id="#+id/button14"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="open"
app:layout_constraintBottom_toBottomOf="#+id/textView14"
app:layout_constraintEnd_toEndOf="#+id/button12"
app:layout_constraintTop_toTopOf="#+id/textView13" />
<Button
android:id="#+id/button15"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="open"
app:layout_constraintBottom_toBottomOf="#+id/textView12"
app:layout_constraintEnd_toEndOf="#+id/button14"
app:layout_constraintTop_toBottomOf="#+id/textView11" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/textView9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/textView18"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView16" />
<Button
android:id="#+id/button4"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/textView11"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView10" />
<Button
android:id="#+id/button5"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/textView13"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView12" />
<Button
android:id="#+id/button6"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/textView15"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView14" />
<Button
android:id="#+id/button7"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/guideline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView17" />
<Button
android:id="#+id/button8"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/guideline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView17" />
<Button
android:id="#+id/button16"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="#+id/guideline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView17" />
</android.support.constraint.ConstraintLayout>
The result will look like this in the preview and on a real device:
And if you survived reading that long answer (I know, its long, who would read all of this?)
Here is something extra
Now, I know that at first look this may look like a lot of work and some may wonder if this is really worth the effort but here is why I believe ConstraintLayout is the proper way to build your UI:
It's really user-friendly.
ConstraintLayout is very easy and simple to learn.
once you have learned it you will see that you are saving a lot of development time because making your UI is simply fast.
Constraint layout is meant to support different screen sizes so no need to build a layout for every screen size (this also connect to the previous advantage- saving development time).
So happy coding, I hope that I could help with my answer.

Categories

Resources