I have a pop-up dialog that is prompted by a button. I recently added a few more categories to be displayed on the screen, and now the dialog is behaving strangely. After I click the prompt, the dialog pops up, but it doesn't remain still; instead, it repeatedly gets thinner then wider, and just moving quickly back and forth. Has anyone else encountered this? Here is the XML code for the pop-up:
<?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="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/productName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="TEST"
android:gravity="center"
android:textSize="25sp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/productImage" />
<TextView
android:id="#+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category"
android:textSize="20sp"
android:gravity="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/productName" />
<TextView
android:id="#+id/size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="size"
app:layout_constraintRight_toLeftOf="#+id/powerType"
android:layout_marginRight="8dp"
app:layout_constraintTop_toTopOf="#+id/powerType"
android:layout_marginTop="0dp" />
<TextView
android:id="#+id/horsepower"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="horsepower"
android:gravity="left"
app:layout_constraintLeft_toRightOf="#+id/voltage"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="#+id/voltage"
android:layout_marginTop="0dp" />
<TextView
android:id="#+id/powerType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="power type"
android:gravity="left"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/category"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="#+id/category"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="#+id/category"
app:layout_constraintHorizontal_bias="0.473" />
<TextView
android:id="#+id/expProof"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="exp Proof"
android:gravity="left"
app:layout_constraintLeft_toRightOf="#+id/powerType"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="#+id/powerType"
android:layout_marginTop="0dp" />
<TextView
android:id="#+id/psi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PSI"
android:gravity="left"
app:layout_constraintRight_toLeftOf="#+id/gpm"
android:layout_marginRight="8dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toTopOf="#+id/gpm" />
<TextView
android:id="#+id/gpm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GPM"
android:gravity="left"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="#+id/voltage"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="#+id/voltage"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="#+id/voltage"
app:layout_constraintHorizontal_bias="0.0" />
<TextView
android:id="#+id/rpm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RPM"
android:gravity="left"
app:layout_constraintLeft_toRightOf="#+id/gpm"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="#+id/gpm"
android:layout_marginTop="0dp" />
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textSize="20sp"
android:gravity="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="#+id/gpm" />
<Button
android:id="#+id/closeDetails"
android:layout_width="#dimen/popUpDetailSections"
android:layout_height="41dp"
android:text="#string/okayButton"
android:gravity="left"
android:textSize="15sp"
android:backgroundTint="#color/colorPrimary"
android:textColor="#color/white"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="#+id/price" />
<ImageView
android:id="#+id/productImage"
android:layout_width="200dp"
android:layout_height="124dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="#drawable/exp_proof_pump_skid"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp" />
<TextView
android:id="#+id/voltage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="voltage"
android:gravity="left"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/powerType"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="#+id/powerType"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="#+id/powerType"
app:layout_constraintHorizontal_bias="0.0" />
<TextView
android:id="#+id/phase"
android:layout_width="wrap_content"
android:layout_height="16dp"
android:text="phase"
android:gravity="left"
app:layout_constraintRight_toLeftOf="#+id/voltage"
android:layout_marginRight="8dp"
app:layout_constraintTop_toTopOf="#+id/voltage"
android:layout_marginTop="0dp" />
</android.support.constraint.ConstraintLayout>
https://i.stack.imgur.com/3scVl.png <- this is a screenshot of the dialog. So the boundaries keep expanding and compressing, and the text keeps moving too.
try this
Window window = customDialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.WRAP_CONTENT);
Related
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>
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>
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.
I am new to android studio and I have been creating a few projects, learning different concepts. I am now making my first application and I've noticed that when I launch all my applications on the emulator, the content doesn't completely cover the application. In my XML, the activity is centered in the app, but on the emulator everything's strangely shifted to the left.
I have posted images below to explain what I am talking about. I was wondering if this is normal, or am I doing something wrong. Since I spent a lot of time laying out the XML activity the way I desire, and then it is displayed awful on the emulator.
This is the Login Page, notice how centered and laid out all the views are.
This is the application launched on the emulator. Notice how the content is constrained, and kind of squeezed and pushed to the top left corner.
How do I fix this issue?
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"
android:background="#drawable/barbell_background"
android:theme="#style/Base.ThemeOverlay.AppCompat.Dark"
tools:context=".Login">
<ImageView
android:id="#+id/AppLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="118dp"
android:layout_marginTop="40dp"
android:adjustViewBounds="true"
android:foregroundGravity="center_horizontal"
android:maxHeight="150dp"
android:maxWidth="150dp"
android:scaleType="fitCenter"
android:src="#drawable/fitness_logo_white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/LoginUsernameLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="30dp"
android:minHeight="50dp"
android:minWidth="300dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/AppLogo">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:minWidth="40dp"
android:src="#drawable/user_icon"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/LoginUsernameInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="240dp"
android:minHeight="50dp"
android:layout_marginStart="5dp"
android:hint="Username"
android:textSize="20sp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/LoginPasswordLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="90dp"
android:minHeight="50dp"
android:minWidth="300dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/AppLogo">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:minWidth="40dp"
android:src="#drawable/password_icon"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/LoginPasswordInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="240dp"
android:minHeight="50dp"
android:layout_marginStart="5dp"
android:hint="Password"
android:textSize="20sp"
android:inputType="textPassword"/>
</LinearLayout>
<Button
android:id="#+id/SignInButton"
android:layout_width="297dp"
android:layout_height="34dp"
android:layout_marginStart="44dp"
android:layout_marginTop="25dp"
android:width="250dp"
android:height="5dp"
android:background="#drawable/login_button_design"
android:gravity="center"
android:text="#string/sign_in"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/LoginPasswordLayout" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="72dp"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/SignInButton">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/don_t_have_an_account"
android:textSize="16sp" />
<EditText
android:id="#+id/SignUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:background="#android:color/transparent"
android:text="#string/sign_up" />
</LinearLayout>
<Button
android:id="#+id/DB_Display_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="92dp"
android:layout_marginTop="32dp"
android:width="200dp"
android:background="#drawable/signup_button_design"
android:gravity="center"
android:text="Display Login Database"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2" />
</android.support.constraint.ConstraintLayout>
You using hard coded values for margins, it will not work on differente resolutions from the one you created it for. You need to use relative sizes for width/height (wrap_content/match_parent) and use gravity to anchor childs relative to its parent (center, left, right, center_horizontal, center_vertical).
margins are used only to add space between views not for centering.
Once you do all this your same screen will work on different screen sizes.
I think you have set all the necessary constraint for all the view. that is why they are getting shifted to the 0,0(top left) location of the screen.
Could you post the whole 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"
android:theme="#style/Base.ThemeOverlay.AppCompat.Dark"
tools:context=".Main2Activity">
<ImageView
android:id="#+id/AppLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="118dp"
android:layout_marginTop="40dp"
android:adjustViewBounds="true"
android:foregroundGravity="center_horizontal"
android:maxHeight="150dp"
android:maxWidth="150dp"
android:scaleType="fitCenter"
android:src="#color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="118dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="8dp" />
<LinearLayout
android:id="#+id/LoginUsernameLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="30dp"
android:minHeight="50dp"
android:minWidth="300dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/AppLogo"
android:layout_marginLeft="40dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="8dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:minWidth="40dp"
android:src="#drawable/user_icon"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/LoginUsernameInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="240dp"
android:minHeight="50dp"
android:layout_marginStart="5dp"
android:hint="Username"
android:textSize="20sp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/LoginPasswordLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:minHeight="50dp"
android:minWidth="300dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="40dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="17dp"
app:layout_constraintTop_toBottomOf="#+id/LoginUsernameLayout"
android:layout_marginEnd="8dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:minWidth="40dp"
android:src="#drawable/password_icon"
android:layout_gravity="center_vertical"/>
<EditText
android:id="#+id/LoginPasswordInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="240dp"
android:minHeight="50dp"
android:layout_marginStart="5dp"
android:hint="Password"
android:textSize="20sp"
android:inputType="textPassword"/>
</LinearLayout>
<Button
android:id="#+id/SignInButton"
android:layout_width="297dp"
android:layout_height="48dp"
android:layout_marginStart="44dp"
android:layout_marginTop="26dp"
android:width="250dp"
android:height="5dp"
android:background="#drawable/login_button_design"
android:gravity="center"
android:text="#string/sign_in"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/LoginPasswordLayout"
android:layout_marginLeft="44dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintHorizontal_bias="0.4" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="59dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/SignInButton"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.154">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/don_t_have_an_account"
android:textSize="16sp" />
<EditText
android:id="#+id/SignUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:background="#android:color/transparent"
android:text="#string/sign_up" />
</LinearLayout>
<Button
android:id="#+id/DB_Display_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="92dp"
android:layout_marginTop="32dp"
android:width="200dp"
android:background="#drawable/signup_button_design"
android:gravity="center"
android:text="Display Login Database"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2"
android:layout_marginLeft="92dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintHorizontal_bias="0.13"
app:layout_constraintVertical_bias="0.029"
android:layout_marginEnd="8dp" />
</android.support.constraint.ConstraintLayout>
I have 3 buttons and I want to make a text field between them,
here is the 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:id="#+id/selecmain"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:elevation="5dp"
android:textAlignment="center"
android:textColor="#514e4e"
android:textSize="20sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:textColor="#514e4e"
android:textSize="20sp"
android:elevation="5dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="#+id/button1"
app:layout_constraintRight_toRightOf="#+id/button1"
app:layout_constraintTop_toBottomOf="#+id/button1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="#+id/et"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="top|center_horizontal"
android:textSize="25sp"
android:gravity="top|left"
android:hint="Write something here."
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="#+id/count"
android:maxLength="140"
android:background="#null">
</EditText>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="140/140"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="#+id/button3"
android:layout_marginBottom="10dp" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:elevation="5dp"
android:onClick="setBtnRecord"
android:text="Record"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:visibility="visible"
android:enabled="false"
android:layout_marginBottom="10dp"
app:layout_constraintLeft_toLeftOf="#id/button2"
app:layout_constraintRight_toRightOf="#id/button2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0" />
</android.support.constraint.ConstraintLayout>
I would like the edittext to fill the space between button2 and button3, but I can't simply make it below the button since I want to have a boarder for the edittext as well. My intention is to let the user know those large area is for them to write something.
In addition, I sometimes will make button2 invisible, but I want the edittext remain the same position just like the button2 is there.
I know it has something to do with the edittext's height, but I am not sure how to make it fit to different screen size or even just in one size.
Try this 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:id="#+id/selecmain"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:elevation="5dp"
android:textAlignment="center"
android:textColor="#514e4e"
android:textSize="20sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:textColor="#514e4e"
android:textSize="20sp"
android:elevation="5dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toBottomOf="#+id/button1"
app:layout_constraintLeft_toLeftOf="#+id/button1"
app:layout_constraintRight_toRightOf="#+id/button1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="#+id/et"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_gravity="top|center_horizontal"
android:textSize="25sp"
android:gravity="top|left"
android:hint="Write something here."
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button2"
app:layout_constraintBottom_toTopOf="#+id/count"
android:maxLength="140"
android:background="#null">
</EditText>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="140/140"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="#+id/button3"
android:layout_marginBottom="10dp" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:elevation="5dp"
android:onClick="setBtnRecord"
android:text="Record"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:visibility="visible"
android:enabled="false"
android:layout_marginBottom="10dp"
app:layout_constraintLeft_toLeftOf="#+id/button1"
app:layout_constraintRight_toRightOf="#+id/button1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0" />