How to make an edittext fit between two buttons? - java

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" />

Related

Buttons Disappear With ScrollView on Android Studio

without ScrollView, my buttons look fine but after I use it, the buttons disappear, I tried a lot at solution but the thing appear is just <TextView>.
How can I make them appear as preferred?
activity_main.xml
<RelativeLayout 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:background="#drawable/background">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/HeaderText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="21dp"
android:gravity="right"
android:hapticFeedbackEnabled="false"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="25"
android:text="HeaderText"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:textColor="#color/white"
app:layout_constraintBottom_toTopOf="#+id/Button1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" />
<Button
android:id="#+id/Button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="#android:drawable/btn_radio"
android:text="Button1"
app:layout_constraintBottom_toTopOf="#+id/Button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/HeaderText"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/Button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="#android:drawable/btn_radio"
android:text="Button2"
app:layout_constraintBottom_toTopOf="#+id/Button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Button1" />
<Button
android:id="#+id/Button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="#android:drawable/btn_radio"
android:text="Button3"
app:layout_constraintBottom_toTopOf="#+id/Button4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Button2" />
<Button
android:id="#+id/Button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="364dp"
android:background="#android:drawable/btn_radio"
android:text="Button4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Button3" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
MainActivity.java is as default.
It works like this:
The problem is that your button widths are zero.
<Button
android:id="#+id/Button2"
android:layout_width="0dp" //<------------- HERE
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="#android:drawable/btn_radio"
android:text="Button2"
app:layout_constraintBottom_toTopOf="#+id/Button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Button1" />
Change the width and you will see them.

Static buttons over top a scroll view android studio

I want to create an activity where i have 2 buttons at the bottom of the screen, and a scroll view above them. Inside of the scroll view i want a drop down menu where the user can select a series of exercises. How do I put the scroll view above the buttons and have them stay in the same spot when scrolling?
Code for activity
<?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:id="#+id/ConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WorkoutsCreater">
<TextView
android:id="#+id/NameWorkoutTextView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:gravity="center"
android:text="Name of Workout:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="#+id/NameWorkoutInput"
app:layout_constraintEnd_toStartOf="#+id/NameWorkoutInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/NameWorkoutInput" />
<TextView
android:id="#+id/nameExercise1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="Exercise 1:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="#id/spinnerExercise1"
app:layout_constraintEnd_toStartOf="#+id/NameWorkoutInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/spinnerExercise1" />
<EditText
android:id="#+id/NameWorkoutInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:inputType="text"
android:maxLength="20"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/NameWorkoutTextView"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/BtnNew"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/circle_plus"
android:clickable="true"
android:focusable="true"
android:foreground="#drawable/ic_add_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/ic_add_white" />
<Button
android:id="#+id/BtnSave"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/rounded_corners"
android:foreground="#drawable/ic_save_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Spinner
android:id="#+id/spinnerExercise1"
android:layout_width="175dp"
android:layout_height="43dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/NameWorkoutInput" />
Image of activity
If you want to add a scrollview that stays above the two buttons, you can add a NestedScrollview inside the constraintlayout
<?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:id="#+id/ConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WorkoutsCreater">
<androidx.core.widget.NestedScrollView
android:layout_width="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#id/BtnNew"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/NameWorkoutTextView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:gravity="center"
android:text="Name of Workout:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="#+id/NameWorkoutInput"
app:layout_constraintEnd_toStartOf="#+id/NameWorkoutInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/NameWorkoutInput" />
<TextView
android:id="#+id/nameExercise1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:gravity="center"
android:text="Exercise 1:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="#id/spinnerExercise1"
app:layout_constraintEnd_toStartOf="#+id/NameWorkoutInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/spinnerExercise1" />
<EditText
android:id="#+id/NameWorkoutInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:inputType="text"
android:maxLength="20"
android:textSize="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/NameWorkoutTextView"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="#+id/spinnerExercise1"
android:layout_width="175dp"
android:layout_height="43dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/NameWorkoutInput" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<Button
android:id="#+id/BtnNew"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/ic_add_circle"
android:clickable="true"
android:focusable="true"
android:foreground="#drawable/ic_add_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/ic_add_white" />
<Button
android:id="#+id/BtnSave"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/ic_remove_red_ba0a00"
android:foreground="#drawable/ic_save_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Disclaimer: Nested layouts are more costlier than flat layouts
Please have a look at this https://developer.android.com/topic/performance/rendering/optimizing-view-hierarchies

Textview over Imageview in a fixed position

I would like to put some textviews over an image in a fixed position.
I tried using relative, contraint and frame layout but what I see in preview does not match on my device.
I tried to use px, sp and dp but it did not help.
Textviews must stay exactly in their position on every device.
Thanks
screen device and android studio layout
xml CODE ADDED:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".b_command">
<RadioGroup
android:id="#+id/radioGroup_conn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/plancia_img"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="USB" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ethernet" />
</RadioGroup>
<RadioGroup
android:id="#+id/Radiogroup_cmd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioGroup_conn">
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Note on/off" />
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prog Change" />
<RadioButton
android:id="#+id/radioButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ctrl Change" />
</RadioGroup>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/plancia_layout"
android:layout_width="363dp"
android:layout_height="225dp"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Radiogroup_cmd">
<ImageView
android:id="#+id/plancia_img"
android:layout_width="363dp"
android:layout_height="225dp"
android:contentDescription="TODO"
android:scaleType="centerCrop"
android:src="#drawable/plancia"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:layout_marginTop="160dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="102dp"
android:layout_marginTop="160dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="265dp"
android:layout_marginTop="160dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_f1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="165dp"
android:layout_marginTop="75dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_f2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="215dp"
android:layout_marginTop="75dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_f3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="265dp"
android:layout_marginTop="75dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/val_f4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="315dp"
android:layout_marginTop="75dp"
android:background="#FFFFFF"
android:backgroundTint="#F8F5F5"
android:gravity="center"
android:padding="2dp"
android:text="#string/basic_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
you can try screen height programmatic to your textview according to your requirement for more detailing answer elaborate your question first.
If I were you, I would use a custom view in which I would simply calculate the necessary coordinates.
https://www.vogella.com/tutorials/AndroidCustomViews/article.html

How do I fix issue on overlapping components in Android Studio?

On my main xml file, I have these four components arranged this way:
<fragment...>
<RelativeLayout...>
<Button...>
<androidx.drawerLayout.widget.DrawerLayout...>
Since the DrawerLayout is on the topmost layer of my whole screen, (although it looks transparent) it covers all of my other components such as those inside the RelativeLayout which makes it impossible to click. However, if I move it to the bottom of the component tree, the RelativeLayout covers it which is also not what I want.
I figured that there could be two ways in which I could solve the issue. First by moving the whole RelativeLayout inside the DrawerLayout resulting to visual error of the RelativeLayout stretching all the way to the top of the screen, or by making the DrawerLayout clickthrough. Which of the two is most efficient way of doing it and how can I do it?
Here is the entire xml file of my activity:
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent"
tools:context=".MapsActivity" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#drawable/white_border"
app:layout_constraintBottom_toBottomOf="#+id/map"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<ImageView
android:id="#+id/markerOrigin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonOrigin"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginTop="-22dp"
android:layout_marginBottom="121dp"
android:contentDescription="#string/originMarkerDescription"
map:srcCompat="#drawable/usersloacationbb" />
<ImageView
android:id="#+id/markerDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonDestination"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="1dp"
android:layout_marginTop="-20dp"
android:layout_marginBottom="61dp"
android:contentDescription="#string/destinationMarkerDescription"
map:layout_constraintBottom_toBottomOf="parent"
map:srcCompat="#drawable/destinationbb" />
<Button
android:id="#+id/buttonOrigin"
android:layout_width="215dp"
android:layout_height="34dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="70dp"
android:layout_marginTop="23dp"
android:layout_marginEnd="25dp"
android:background="#drawable/search_shape"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:id="#+id/buttonDestination"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_above="#+id/buttonTara"
android:layout_below="#+id/buttonOrigin"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="69dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="26dp"
android:layout_marginBottom="25dp"
android:background="#drawable/search_shape"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:id="#+id/buttonTara"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="25dp"
android:layout_marginBottom="24dp"
android:background="#drawable/button_tara"
android:fontFamily="#font/bold"
android:text="#string/buttonTara"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="15sp"
style="?android:attr/borderlessButtonStyle"/>
</RelativeLayout>
<Button
android:id="#+id/buttonDrawer"
style="?android:attr/borderlessButtonStyle"
android:layout_width="52dp"
android:layout_height="35dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="20dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="270dp"
android:background="#drawable/search_shape"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent" />
<androidx.drawerlayout.widget.DrawerLayout
android:id="#+id/drawerLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/navigation_drawer">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
Here's how it looks like with the DrawerLayout on the topmost layer:
Correct display but unclickable components
Here's how it looks like with RelativeLayout inside the DrawerLayout:
Correct arrangement of components but with padding issues on the button
Here's how it looks like with the DrawerLayout on the bottom:
DrawerLayout below other components
Any help is appreciated!
For clickable content and on top drawer you must move ConstraintLayout
into DrawerLayout like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
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/drawerLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/map"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#android:color/darker_gray"
app:layout_constraintBottom_toBottomOf="#+id/map"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<ImageView
android:id="#+id/markerOrigin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonOrigin"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginTop="-22dp"
android:layout_marginBottom="121dp"
android:contentDescription="originMarkerDescription"
app:srcCompat="#drawable/common_google_signin_btn_icon_dark_normal" />
<ImageView
android:id="#+id/markerDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonDestination"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="1dp"
android:layout_marginTop="-20dp"
android:layout_marginBottom="61dp"
android:contentDescription="destinationMarkerDescription"
app:layout_constraintBottom_toBottomOf="parent"
app:srcCompat="#drawable/common_full_open_on_phone" />
<Button
android:id="#+id/buttonOrigin"
style="?android:attr/borderlessButtonStyle"
android:layout_width="215dp"
android:layout_height="34dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="70dp"
android:layout_marginTop="23dp"
android:layout_marginEnd="25dp"
android:text="lk;'kl;'" />
<Button
android:id="#+id/buttonDestination"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_above="#+id/buttonTara"
android:layout_below="#+id/buttonOrigin"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="69dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="26dp"
android:layout_marginBottom="25dp"
android:text="lk;'kl;'"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/buttonTara"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="25dp"
android:layout_marginBottom="24dp"
android:text="buttonTara"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="15sp" />
</RelativeLayout>
<Button
android:id="#+id/buttonDrawer"
style="?android:attr/borderlessButtonStyle"
android:layout_width="52dp"
android:layout_height="35dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="20dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="270dp"
android:text="lk;'kl;'"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:layout_gravity="start"
android:layout_height="match_parent"
android:layout_width="wrap_content"
app:menu="#menu/main"></com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>

Android Dialog keeps fidgeting - won't remain one size

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);

Categories

Resources