Android Native Preview diffrent with Real preview - android

I'm doing a homework task.
I already tried with relative or liner, event constraint layout
but preview is always different from the real preview in my phone.
My phone is Xiaomi Redmi Note 5a (55 inch, 1280 x 720 pixel)
My device
Android Studio preview
<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=".Register"
tools:layout_editor_absoluteY="25dp">
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:background="#drawable/ic_header" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="27dp"
android:layout_height="30dp"
android:background="#drawable/ic_header_back"
tools:layout_editor_absoluteX="15dp"
tools:layout_editor_absoluteY="15dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:textColor="#FFFFFF"
android:textSize="20dp"
android:textStyle="bold"
tools:layout_editor_absoluteX="55dp"
tools:layout_editor_absoluteY="16dp" />
<EditText
android:id="#+id/editText3"
android:layout_width="328dp"
android:layout_height="34dp"
android:backgroundTint="#808284"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
android:text=""
android:textColorHint="#808284"
android:textSize="10dp"
android:typeface="normal"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="72dp" />
<EditText
android:id="#+id/editText10"
android:layout_width="330dp"
android:layout_height="34dp"
android:backgroundTint="#808284"
android:ems="10"
android:hint="Home Address"
android:inputType="text"
android:text=""
android:textColorHint="#808284"
android:textSize="10dp"
android:typeface="normal"
tools:layout_editor_absoluteX="15dp"
tools:layout_editor_absoluteY="395dp" />
full code : https://pastebin.com/U9YdKK1m

You see this layout differently because you are using fixed size on your views, and different phones got different screen size - so using fixed size will make your layout non-responsive to all devices.
If you want to use constraintLayot you can simply use chains to order your views vertically:
<?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">
<ImageView
android:id="#+id/imageView3"
android:layout_width="27dp"
android:layout_height="30dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="#+id/textView3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.571" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:text="Register"
android:textColor="#FFFFFF"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/imageView3"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/editText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#808284"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
android:text=""
android:textColorHint="#808284"
android:textSize="10dp"
android:typeface="normal"
app:layout_constraintBottom_toTopOf="#+id/editText10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView3" />
<EditText
android:id="#+id/editText10"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#808284"
android:ems="10"
android:hint="Home Address"
android:inputType="text"
android:text=""
android:textColorHint="#808284"
android:textSize="10dp"
android:typeface="normal"
app:layout_constraintBottom_toTopOf="#+id/editText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText3" />
<EditText
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#808284"
android:ems="10"
android:hint="Home Address"
android:inputType="text"
android:text=""
android:textColorHint="#808284"
android:textSize="10dp"
android:typeface="normal"
app:layout_constraintBottom_toTopOf="#+id/radioButton2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText10" />
<RadioButton
android:id="#+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton"
app:layout_constraintBottom_toBottomOf="#+id/radioButton2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/radioButton2"
app:layout_constraintTop_toTopOf="#+id/radioButton2" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="RadioButton"
app:layout_constraintBottom_toTopOf="#+id/guideline4"
app:layout_constraintEnd_toStartOf="#+id/radioButton"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
It will look like this :

Related

Layout displays differently on emulator and android than it should

The layout is displayed differently in the design and differently in the emulator and on the android. I am new and i cant figure out why is it.
<EditText
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:autofillHints=""
android:ems="10"
android:hint="Your login"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.099"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Your password"
android:importantForAutofill="no"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/login" />
<EditText
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Your email"
android:importantForAutofill="no"
android:inputType="textEmailAddress"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/password" />
<TextView
android:id="#+id/emailWarrning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="156dp"
android:text="fwef"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toEndOf="#+id/email"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/passwordWarrning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="92dp"
android:text="duap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/password"
app:layout_constraintTop_toTopOf="parent" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="316dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent">
<RadioButton
android:id="#+id/radioButton9"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Female" />
<RadioButton
android:id="#+id/radioButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="#+id/radioButton8"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Shemale" />
</RadioGroup>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:text="Set your sex:"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="#+id/radioGroup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
while learning from youtube, I still face problems with some strange problems, despite the fact that I am doing it step by step as in the tutorial
You see the difference between design view and emulator as screen size is different. RadioGroup is shifting up because of android:layout_marginBottom="316dp".Remove this hard margin and add top constraint for RadioGroup so that its always below textView6 .
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/textView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent">
Also adjust textView6 constraints so that its always below email view.
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:text="Set your sex:"
android:textSize="24sp"
app:layout_constraintTop_toBottomOf="#id/email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
Add some margin between email and textView6 if you wish.
Also remove top margins for emailWarning and passwordWarning and align these views to email and password views by changing constraints as below .
<TextView
android:id="#+id/emailWarrning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fwef"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toEndOf="#+id/email"
app:layout_constraintTop_toTopOf="#id/email" />
<TextView
android:id="#+id/passwordWarrning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="duap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/password"
app:layout_constraintTop_toTopOf="#id/password" />

Difficulties Pertaining to Catering to Multiple Phone Screen Sizes

I am currently working on an application and am trying to allow it to support multiple phone screen sizes (it will not support anything larger than a Google Pixel 3 XL). Also, just for context, I'm using a ConstraintLayout.
For the background of the layout I'm using an image. On top of the background, I have interact-able elements meticulously placed to match the position they're supposed to correspond with on the background. This, however, doesn't translate well across all displays, as the layout elements and the background become distorted and misaligned. My solution to this was to try to make different layouts for phones which would be applied based on their resolution (layouts were made for phones with these screen dimensions: 1080x1920, 1080x2160, 1440x2560, 1440x2880, 1440x2960).
However, these don't seem to auto-apply to any of the devices I've tested on. I'm assuming this is because phones don't have any specifications and this only really applies to tablets, watches, etc. I just recently thought of transferring everything from my UI into my layout and to just implement everything using ImageViews, but this doesn't work either, since when the phone
screen size changes, all elements lose their proper placement within the screen. I've tried almost everything and can't quite think of anything else to do in order to make my app cater to all screen sizes.
I'll provide one of my more complicated layouts for reference. Really hoping for some help on this one. Thanks!
Layout
<?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"
android:orientation="vertical"
android:background="#drawable/a1440x2960_tt">
<TextView
android:id="#+id/display"
android:layout_width="wrap_content"
android:layout_height="74dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="152dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:fontFamily="#font/freesansbold"
android:text="00 : 00 . 00"
android:textColor="#color/black"
android:textSize="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/resetbtn"
android:layout_width="83dp"
android:layout_height="34dp"
android:layout_marginStart="268dp"
android:layout_marginLeft="268dp"
android:layout_marginTop="264dp"
android:background="#color/transparent"
android:stateListAnimator="#null"
android:textAllCaps="false"
android:textColor="#color/stopbtn"
android:textSize="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/pausebtn"
android:layout_width="92dp"
android:layout_height="35dp"
android:layout_marginStart="156dp"
android:layout_marginLeft="156dp"
android:layout_marginTop="264dp"
android:background="#color/transparent"
android:stateListAnimator="#null"
android:textAllCaps="false"
android:textColor="#color/stopbtn"
android:textSize="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/goalMinutes"
android:layout_width="96dp"
android:layout_height="66dp"
android:layout_marginStart="48dp"
android:layout_marginLeft="48dp"
android:layout_marginTop="156dp"
android:background="#null"
android:fontFamily="#font/freesansbold"
android:inputType="numberPassword"
android:text="00"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="50dp"
app:layout_constraintStart_toStartOf="#+id/splashdebugoutput"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/goalMilli"
android:layout_width="93dp"
android:layout_height="66dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="156dp"
android:background="#null"
android:fontFamily="#font/freesansbold"
android:inputType="numberPassword"
android:text="00"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="50dp"
app:layout_constraintStart_toStartOf="#+id/goal_dot"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/goalSeconds"
android:layout_width="82dp"
android:layout_height="66dp"
android:layout_marginTop="156dp"
android:background="#null"
android:fontFamily="#font/freesansbold"
android:inputType="numberPassword"
android:text="00"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="50dp"
app:layout_constraintStart_toEndOf="#+id/goal_colon2"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/goal_dot"
android:layout_width="16dp"
android:layout_height="67dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="156dp"
android:fontFamily="#font/product_bold"
android:text="."
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="50dp"
app:layout_constraintStart_toEndOf="#+id/goalSeconds"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/goal_colon"
android:layout_width="18dp"
android:layout_height="43dp"
android:layout_marginStart="28dp"
android:layout_marginLeft="28dp"
android:layout_marginTop="457dp"
android:fontFamily="#font/product_bold"
android:text=":"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="24dp"
app:layout_constraintStart_toStartOf="#+id/tempoSeconds"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/goal_colon2"
android:layout_width="16dp"
android:layout_height="67dp"
android:layout_marginTop="152dp"
android:fontFamily="#font/product_bold"
android:text=":"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="50dp"
app:layout_constraintStart_toEndOf="#+id/goalMinutes"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/minmarker"
android:layout_width="15dp"
android:layout_height="21dp"
android:layout_marginStart="42dp"
android:layout_marginLeft="42dp"
android:layout_marginTop="64dp"
android:fontFamily="#font/product_regular"
android:text="M"
android:textColor="#color/black"
android:textSize="17dp"
app:layout_constraintStart_toStartOf="#+id/goalMinutes"
app:layout_constraintTop_toTopOf="#+id/goalMinutes" />
<TextView
android:id="#+id/secmarker"
android:layout_width="12dp"
android:layout_height="20dp"
android:layout_marginStart="148dp"
android:layout_marginLeft="148dp"
android:layout_marginTop="64dp"
android:fontFamily="#font/product_regular"
android:text="S"
android:textColor="#color/black"
android:textSize="17dp"
app:layout_constraintStart_toStartOf="#+id/goalMinutes"
app:layout_constraintTop_toTopOf="#+id/goalMinutes" />
<TextView
android:id="#+id/millimarker"
android:layout_width="27dp"
android:layout_height="19dp"
android:layout_marginStart="246dp"
android:layout_marginLeft="246dp"
android:layout_marginTop="64dp"
android:fontFamily="#font/product_regular"
android:text="MS"
android:textColor="#color/black"
android:textSize="17dp"
app:layout_constraintStart_toStartOf="#+id/goalMinutes"
app:layout_constraintTop_toTopOf="#+id/goalMinutes" />
<TextView
android:id="#+id/splashdebugoutput"
android:layout_width="wrap_content"
android:layout_height="37dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Spinner
android:id="#+id/course"
android:layout_width="118dp"
android:layout_height="36dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="233dp"
android:layout_marginRight="233dp"
android:background="#color/transparent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/resetbtn"></Spinner>
<Spinner
android:id="#+id/length"
android:layout_width="118dp"
android:layout_height="38dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="68dp"
android:layout_marginRight="68dp"
android:background="#color/transparent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/resetbtn"></Spinner>
<Button
android:id="#+id/startbtn"
android:layout_width="86dp"
android:layout_height="35dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="#color/transparent"
app:layout_constraintEnd_toStartOf="#+id/pausebtn"
app:layout_constraintHorizontal_bias="0.741"
app:layout_constraintStart_toStartOf="#+id/splashdebugoutput"
app:layout_constraintTop_toBottomOf="#+id/goalMinutes" />
<EditText
android:id="#+id/tempoSeconds"
android:layout_width="30dp"
android:layout_height="47dp"
android:layout_marginStart="68dp"
android:layout_marginLeft="68dp"
android:layout_marginTop="448dp"
android:backgroundTint="#color/black"
android:maxLength="1"
android:ems="10"
android:fontFamily="#font/product_regular"
android:hint="0"
android:inputType="numberPassword"
android:textAlignment="center"
android:textColor="#color/black"
android:textColorHint="#color/texthint"
android:textSize="15dp"
android:verticalScrollbarPosition="right"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/tempoMilliTens"
android:layout_width="29dp"
android:layout_height="48dp"
android:layout_marginTop="448dp"
android:backgroundTint="#color/black"
android:ems="10"
android:fontFamily="#font/product_regular"
android:hint="0"
android:inputType="numberPassword"
android:maxLength="1"
android:textAlignment="center"
android:textColor="#color/black"
android:textColorHint="#color/texthint"
android:textSize="15dp"
app:layout_constraintStart_toEndOf="#+id/goal_colon"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/tempoMilliHundreds"
android:layout_width="30dp"
android:layout_height="48dp"
android:layout_marginTop="448dp"
android:backgroundTint="#color/black"
android:ems="10"
android:fontFamily="#font/product_regular"
android:hint="0"
android:maxLength="1" android:inputType="numberPassword"
android:textAlignment="center"
android:textColor="#color/black"
android:textColorHint="#color/texthint"
android:textSize="15dp"
app:layout_constraintStart_toEndOf="#+id/tempoMilliTens"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="#+id/splitAuto"
android:layout_width="174dp"
android:layout_height="26dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:button="#color/transparent"
android:background="#null"
android:scaleX="1.35"
android:scaleY="1.35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/course" />
<CheckBox
android:id="#+id/splitManual"
android:layout_width="174dp"
android:layout_height="26dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:button="#color/transparent"
android:scaleX="1.35"
android:background="#null"
android:scaleY="1.35"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/splitAuto" />
<ImageView
android:id="#+id/checked1"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="153dp"
android:layout_marginRight="151dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/course" />
<ImageView
android:id="#+id/checked2"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginTop="87dp"
android:layout_marginEnd="153dp"
android:layout_marginRight="148dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/length" />
<ImageView
android:id="#+id/checked1u"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="153dp"
android:layout_marginRight="148dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/course" />
<ImageView
android:id="#+id/checked2u"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginTop="87dp"
android:layout_marginEnd="153dp"
android:layout_marginRight="152dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/length" />
<EditText
android:id="#+id/secInput"
android:layout_width="69dp"
android:layout_height="39dp"
android:layout_marginStart="132dp"
android:layout_marginLeft="132dp"
android:layout_marginTop="76dp"
android:backgroundTint="#color/black"
android:ems="10"
android:fontFamily="#font/product_regular"
android:hint="Sec."
android:inputType="numberPassword"
android:textAlignment="center"
android:textColor="#color/black"
android:textColorHint="#color/black"
android:textSize="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/splitAuto" />
<EditText
android:id="#+id/milliInput"
android:layout_width="69dp"
android:layout_height="39dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="76dp"
android:layout_marginEnd="132dp"
android:layout_marginRight="132dp"
android:backgroundTint="#color/black"
android:ems="10"
android:fontFamily="#font/product_regular"
android:hint="Milli."
android:inputType="numberPassword"
android:textAlignment="center"
android:textColor="#color/black"
android:textColorHint="#color/black"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="#id/secInput"
app:layout_constraintTop_toBottomOf="#+id/splitAuto" />
<EditText
android:id="#+id/offset"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="76dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:backgroundTint="#color/black"
android:ems="10"
android:fontFamily="#font/product_regular"
android:hint="Time Offset Per Length"
android:inputType="numberPassword"
android:textAlignment="center"
android:textColor="#color/black"
android:textColorHint="#color/black"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.507"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/splitAuto" />
<Button
android:id="#+id/add"
android:layout_width="101dp"
android:layout_height="35dp"
android:layout_marginStart="292dp"
android:layout_marginLeft="292dp"
android:layout_marginTop="124dp"
android:background="#color/transparent"
app:layout_constraintStart_toStartOf="#+id/splashdebugoutput"
app:layout_constraintTop_toBottomOf="#+id/splitManual" />
<Button
android:id="#+id/remove"
android:layout_width="101dp"
android:layout_height="35dp"
android:layout_marginTop="4dp"
android:background="#color/transparent"
app:layout_constraintEnd_toEndOf="#+id/add"
app:layout_constraintTop_toBottomOf="#+id/add" />
<ListView
android:id="#+id/splitList"
android:layout_width="113dp"
android:layout_height="95dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="140dp"
android:divider="#color/black"
android:dividerHeight="1dp"
android:scrollbarThumbVertical="#drawable/gray_scroll_style"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"></ListView>
<TextView
android:id="#+id/txtData"
android:layout_width="136dp"
android:layout_height="69dp"
android:layout_marginStart="132dp"
android:layout_marginLeft="132dp"
android:text="1"
android:visibility="invisible"
android:textColor="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/debugOutput2"
android:layout_width="96dp"
android:layout_height="69dp"
android:text="TextView"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Seems like you have a lot of hard coded density pixels there. Have you tried using dimen.xml?

Background Image gone compressed when keyboard is open

I am making signup page using this image background.
Background image
It Look like: Signup page
But when I focus on EditText and when keyboard is opened, the background image is compressed. How can I resolve this.
After Compressed :
Here XML code:
<?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"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/log_sign_bg">
</RelativeLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="260dp">
<EditText
android:id="#+id/editText"
style="#android:style/TextAppearance.Material.Medium"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="#drawable/edittext_background"
android:hint="Username"
android:inputType="textPersonName"
android:paddingLeft="8dp"
android:textAppearance="#android:style/TextAppearance.Material.Medium"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/editText3"
style="#android:style/TextAppearance.Material.Medium"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="16dp"
android:background="#drawable/edittext_background"
android:hint="Email"
android:inputType="textEmailAddress"
android:paddingLeft="8dp"
android:textAppearance="#android:style/TextAppearance.Material.Medium"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="#+id/editText"
app:layout_constraintStart_toStartOf="#+id/editText"
app:layout_constraintTop_toBottomOf="#+id/editText" />
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="16dp"
android:background="#drawable/edittext_background"
android:hint="Password"
android:inputType="textPassword"
android:paddingLeft="8dp"
android:textAppearance="#android:style/TextAppearance.Material.Medium"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="#+id/editText3"
app:layout_constraintStart_toStartOf="#+id/editText3"
app:layout_constraintTop_toBottomOf="#+id/editText3" />
<EditText
android:id="#+id/editText4"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="16dp"
android:background="#drawable/edittext_background"
android:hint="Re-enter Password"
android:inputType="textPassword"
android:paddingLeft="8dp"
android:textAppearance="#android:style/TextAppearance.Material.Medium"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="#+id/editText2"
app:layout_constraintStart_toStartOf="#+id/editText2"
app:layout_constraintTop_toBottomOf="#+id/editText2" />
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginStart="64dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="64dp"
android:background="#drawable/button_background"
android:text="Register"
android:textAppearance="#android:style/TextAppearance.Material.Large"
android:textColor="#FFF"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="#+id/editText4"
app:layout_constraintStart_toStartOf="#+id/editText4"
app:layout_constraintTop_toBottomOf="#+id/editText4" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="24dp"
android:text="Already a member?"
android:textColor="#A6A6A6"
android:textSize="22dp"
app:layout_constraintEnd_toStartOf="#+id/textView2"
app:layout_constraintStart_toStartOf="#+id/button"
app:layout_constraintTop_toBottomOf="#+id/button" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="24dp"
android:text="Login"
android:textColor="#EF3646"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="#+id/button"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/button" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I tried to many ways but i think i have to separate the bakgrounf image and the logo one may be fix it.
Into your AndroidManifest.xml file add below line to your activity
android:windowSoftInputMode="stateVisible|adjustPan"
Like below snippet register in
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateVisible|adjustPan|adjustResize" />
You mentioned issue in comment section so solution is here,
Run time Set Edittext Hint:
EditText etName;
etName= (EditText) findViewById(R.id.etName);
etName.setHint("Your Hint");
Your xml file is not correct ScrollView can not contain multiple child, i have resolved your problem.So Please follow my answer.
if you want to scroll only view not top image then use this one
<?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"
android:fillViewport="true"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/signup_bg"
>
<EditText
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_marginTop="260dp"
android:layout_marginEnd="16dp"
android:hint="Username"
android:inputType="textPersonName"
android:paddingLeft="8dp"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/editText3"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="16dp"
android:hint="Email"
android:inputType="textEmailAddress"
android:paddingLeft="8dp"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="#+id/editText"
app:layout_constraintStart_toStartOf="#+id/editText"
app:layout_constraintTop_toBottomOf="#+id/editText" />
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="16dp"
android:hint="Password"
android:inputType="textPassword"
android:paddingLeft="8dp"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="#+id/editText3"
app:layout_constraintStart_toStartOf="#+id/editText3"
app:layout_constraintTop_toBottomOf="#+id/editText3" />
<EditText
android:id="#+id/editText4"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="16dp"
android:hint="Re-enter Password"
android:inputType="textPassword"
android:paddingLeft="8dp"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="#+id/editText2"
app:layout_constraintStart_toStartOf="#+id/editText2"
app:layout_constraintTop_toBottomOf="#+id/editText2" />
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginStart="64dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="64dp"
android:background="#EF3646"
android:text="Register"
android:textColor="#FFF"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="#+id/editText4"
app:layout_constraintStart_toStartOf="#+id/editText4"
app:layout_constraintTop_toBottomOf="#+id/editText4" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="24dp"
android:text="Already a member?"
android:textColor="#A6A6A6"
android:textSize="22dp"
app:layout_constraintEnd_toStartOf="#+id/textView2"
app:layout_constraintStart_toStartOf="#+id/button"
app:layout_constraintTop_toBottomOf="#+id/button" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="24dp"
android:text="Login"
android:textColor="#EF3646"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="#+id/button"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/button" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Android layout not matching with device [Android Studio]

Hi I am new to using android studio and I do not get why the layout that I am seeing in the preview of the IDE does not match with the ones that I am seeing on my screen. I am using Samsung J7 Prime.
This is what I see in the preview
however, this is what I see on my device.
Please help, thank you in advance.
<?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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="65dp"
android:layout_marginEnd="32dp"
android:text="#string/original_price"
app:layout_constraintBaseline_toBaselineOf="#+id/etNum1"
app:layout_constraintEnd_toStartOf="#+id/etNum1"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="72dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="60dp"
android:text="#string/rate"
app:layout_constraintEnd_toStartOf="#+id/etNum2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/etNum2" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="65dp"
android:layout_marginEnd="61dp"
android:text="#string/discount"
app:layout_constraintEnd_toStartOf="#+id/etNum3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/etNum3" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="65dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="46dp"
android:text="#string/sales_price"
app:layout_constraintEnd_toStartOf="#+id/etNum4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/etNum4" />
<EditText
android:id="#+id/etNum1"
android:layout_width="0dp"
android:layout_height="39dp"
android:layout_marginTop="101dp"
android:layout_marginEnd="75dp"
android:autofillHints=""
android:ems="10"
android:inputType="number"
android:labelFor="#id/etNum1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/etNum2"
android:layout_width="0dp"
android:layout_height="37dp"
android:layout_marginTop="79dp"
android:layout_marginEnd="72dp"
android:layout_marginBottom="80dp"
android:autofillHints=""
android:ems="10"
android:inputType="number"
android:labelFor="#id/etNum2"
app:layout_constraintBottom_toBottomOf="#+id/etNum3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toTopOf="#+id/textView" />
<EditText
android:id="#+id/etNum3"
android:layout_width="0dp"
android:layout_height="34dp"
android:layout_marginTop="143dp"
android:layout_marginEnd="76dp"
android:layout_marginBottom="143dp"
android:autofillHints=""
android:ems="10"
android:inputType="number"
android:labelFor="#id/etNum3"
app:layout_constraintBottom_toTopOf="#+id/calculate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView"
android:editable="false"/>
<EditText
android:id="#+id/etNum4"
android:layout_width="0dp"
android:layout_height="39dp"
android:layout_marginTop="47dp"
android:layout_marginEnd="72dp"
android:autofillHints=""
android:ems="10"
android:inputType="number"
android:labelFor="#id/etNum4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView4"
app:layout_constraintTop_toBottomOf="#+id/etNum3"
android:editable="false"/>
<Button
android:id="#+id/calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginBottom="229dp"
android:text="#string/compute"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView4" />
<Button
android:id="#+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="29dp"
android:text="#string/erase"
app:layout_constraintStart_toStartOf="#+id/calculate"
app:layout_constraintTop_toBottomOf="#+id/calculate" />
</android.support.constraint.ConstraintLayout>
You are using a fixed size in a lot of places for your views(for example android:layout_marginTop="79dp" and android:layout_height="37dp").
Because different phones got different screen size, when you are using a fixed size on your view you are making your layout less responsive.
If you want to place some view anywhere at your screen I would recommend using guielines and constraint your views into the guideline rather then give your view a fixed size value to fit the preview(don't forget that with fixed sizes what may fit one screen may not fit another screen).
For your desired layout you can simply use chains.
Here is an example of the layout that you want to achieve using cnostraintLayout and chains:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/original_price"
app:layout_constraintBottom_toTopOf="#+id/textView2"
app:layout_constraintEnd_toStartOf="#+id/etNum1"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/rate"
app:layout_constraintBottom_toTopOf="#+id/textView3"
app:layout_constraintEnd_toEndOf="#+id/textView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/discount"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintEnd_toEndOf="#+id/textView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/sales_price"
app:layout_constraintBottom_toTopOf="#+id/calculate"
app:layout_constraintEnd_toEndOf="#+id/textView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<EditText
android:id="#+id/etNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autofillHints=""
android:ems="10"
android:inputType="number"
android:labelFor="#id/etNum1"
app:layout_constraintBottom_toBottomOf="#+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toTopOf="#+id/textView" />
<EditText
android:id="#+id/etNum2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints=""
android:ems="10"
android:inputType="number"
android:labelFor="#id/etNum2"
app:layout_constraintBottom_toBottomOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="#+id/etNum1"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/etNum1"
app:layout_constraintTop_toTopOf="#+id/textView2" />
<EditText
android:id="#+id/etNum3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints=""
android:editable="false"
android:ems="10"
android:inputType="number"
android:labelFor="#id/etNum3"
app:layout_constraintBottom_toBottomOf="#+id/textView3"
app:layout_constraintEnd_toEndOf="#+id/etNum1"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/etNum1"
app:layout_constraintTop_toTopOf="#+id/textView3" />
<EditText
android:id="#+id/etNum4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints=""
android:editable="false"
android:ems="10"
android:inputType="number"
android:labelFor="#id/etNum4"
app:layout_constraintBottom_toBottomOf="#+id/textView4"
app:layout_constraintEnd_toEndOf="#+id/etNum1"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/etNum1"
app:layout_constraintTop_toTopOf="#+id/textView4" />
<Button
android:id="#+id/calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="compute"
app:layout_constraintBottom_toTopOf="#+id/clear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<Button
android:id="#+id/clear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="erase"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/calculate"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/calculate"
app:layout_constraintTop_toBottomOf="#+id/calculate" />
</android.support.constraint.ConstraintLayout>
And it will look like this:
Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title 1" />
<EditText
android:id="#+id/etNum1"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginStart="20dp"
android:ems="10"
android:hint="Title 1"
android:inputType="number"
android:labelFor="#id/etNum1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title 2" />
<EditText
android:id="#+id/etNum2"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginStart="20dp"
android:ems="10"
android:hint="Title 2"
android:inputType="number"
android:labelFor="#id/etNum1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title 3" />
<EditText
android:id="#+id/etNum3"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginStart="20dp"
android:ems="10"
android:hint="Title 3"
android:inputType="number"
android:labelFor="#id/etNum1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title 4" />
<EditText
android:id="#+id/etNum4"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginStart="20dp"
android:ems="10"
android:hint="Title 4"
android:inputType="number"
android:labelFor="#id/etNum1" />
</LinearLayout>
<Button
android:id="#+id/calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:text="Button 1" />
<Button
android:id="#+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:text="Button 2" />
</LinearLayout>
Remove all constraints top of and remap them according to what should be on top of for example textView should be on top of textView1 Goodluck

need help figuring out how to compare user input and pulling data from a website using an api key

This is my first time programming in android studio and I need help in figuring out how to compare options selected by the user based on the radio buttons and query an api to pull data from a website. Below is the code of the layout.The results are supposed to be displayed on another page, thank you.
<?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="#0663ba"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="81dp">
<Button
android:id="#+id/button"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#000000"
android:text="#string/search"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText3" />
<EditText
android:id="#+id/editText"
android:layout_width="172dp"
android:layout_height="50dp"
android:layout_marginBottom="32dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:ems="10"
android:hint="#string/zip_code"
android:inputType="textPostalAddress"
app:layout_constraintBottom_toTopOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.04"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/textView2"
android:layout_width="175dp"
android:layout_height="44dp"
android:layout_marginBottom="48dp"
android:layout_marginStart="8dp"
android:fontFamily="sans-serif"
android:text="#string/select_date_range"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/textView3"
app:layout_constraintStart_toStartOf="parent" />
<RadioGroup
android:id="#+id/radioGroup6"
android:layout_width="144dp"
android:layout_height="0dp"
android:layout_marginBottom="14dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textColor="#FFFFFF"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/radioGroup7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/imageButton">
<RadioButton
android:id="#+id/radioButton8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:checked="true"
android:text="#string/_1_week"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<RadioButton
android:id="#+id/radioButton9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/_2_weeks"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<RadioButton
android:id="#+id/radioButton7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/_3_months"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</RadioGroup>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_marginBottom="28dp"
android:layout_marginStart="16dp"
android:text="#string/select_crime_type"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent" />
<RadioGroup
android:id="#+id/radioGroup7"
android:layout_width="144dp"
android:layout_height="0dp"
android:layout_marginBottom="11dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:textColor="#FFFFFF"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/radioGroup6">
<RadioButton
android:id="#+id/radioButton13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/rape"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<RadioButton
android:id="#+id/radioButton15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/assault"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<RadioButton
android:id="#+id/radioButton14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="#string/murder"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</RadioGroup>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="33dp"
android:text="#string/search_for_criminal_or_victim"
android:textAlignment="viewStart"
android:textAppearance="#style/TextAppearance.AppCompat"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/editText3"
app:layout_constraintEnd_toEndOf="#+id/radioGroup7"
app:layout_constraintTop_toBottomOf="#+id/radioGroup7" />
<EditText
android:id="#+id/editText3"
android:layout_width="195dp"
android:layout_height="45dp"
android:layout_marginBottom="66dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:ems="10"
android:hint="#string/enter_full_name"
android:inputType="textPersonName"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="147dp"
android:layout_marginBottom="76dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:backgroundTint="#a91818"
android:scaleType="fitCenter"
android:src="#drawable/new_crime_img"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/radioGroup6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>

Categories

Resources