Textview over Imageview in a fixed position - java

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

Related

Soft Keyboard overlaps Edit text field. Tried all the generic solutions

I have tried all the solutions i.e adding adjustPan and adjustResize in manifest.xml adding fitsSystem window true nd all that the soft keyboard still overlaps Here is my code for better context.
Xml for items in recycler view
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_marginBottom="6dp"
android:fitsSystemWindows="true"
>
<LinearLayout
android:id="#+id/layout_question"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1"
android:fitsSystemWindows="true">
<TextView
android:id="#+id/question_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:padding="#dimen/dimen_10_dp"
android:paddingLeft="#dimen/dimen_5_dp"
android:layout_marginEnd="#dimen/dimen_5_dp"
tools:text="Q1)"
android:layout_marginStart="#dimen/dimen_5_dp"
android:textColor="#000000"
android:fontFamily="#font/work_sans_semibold"
android:textSize="17sp"
/>
<TextView
android:id="#+id/tv_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/dimen_5_dp"
android:layout_marginEnd="#dimen/dimen_5_dp"
android:layout_weight="0.4"
android:lineSpacingExtra="9dp"
android:padding="5dp"
android:paddingLeft="#dimen/dimen_5_dp"
android:text="#{questionName}"
android:textColor="#000000"
android:fontFamily="#font/work_sans_light"
android:textSize="22sp"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="9dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
app:visibleGone="#{isSubjectiveMarks}">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_marginStart="30dp"
android:background="#drawable/bg_border_edittext"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="#+id/et_marks"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/dimen_5_dp"
android:layout_marginEnd="#dimen/dimen_5_dp"
android:background="#drawable/bg_border_edittext"
android:fontFamily="sans-serif"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLength="4"
android:overScrollMode="always"
android:padding="3dp"
android:textColor="#000"
android:textSize="29sp" />
</LinearLayout>
<TextView
android:id="#+id/tv_total_marks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginEnd="24dp"
android:fontFamily="#font/work_sans"
android:gravity="end|right"
android:padding="#dimen/dimen_10_dp"
android:text="#{`Out of ` + totalMarks}"
android:textColor="#4D89EB"
android:textSize="17sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:visibleGone="#{isSubjectiveMarks}"
tools:text="Outof 10" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/subjective_hint_text"
android:orientation="vertical"
app:visibleGone="#{isSubjective}">
<EditText
android:id="#+id/et_question"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginStart="#dimen/dimen_15_dp"
android:layout_marginEnd="#dimen/dimen_15_dp"
android:enabled="#{isViewMode}"
android:gravity="top|start"
android:imeOptions="actionSend|flagNoEnterAction"
android:inputType="textMultiLine"
android:maxLength="3000"
android:background="#drawable/desc_answer_bg"
android:fontFamily="#font/work_sans"
android:textColor="#202124"
android:textSize="21sp"
android:overScrollMode="always"
android:padding="10dp"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:singleLine="false"
android:text="#={subjectiveAnswerText}"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</com.google.android.material.textfield.TextInputLayout>
<RadioGroup
android:id="#+id/rg_answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dimen_5_dp"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
android:clickable="#{isViewMode}"
app:listToRadioGroup="#{optionDataWithAnswer}"
app:visibleGone="#{isObjective}"
/>
<LinearLayout
android:id="#+id/ll_cb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dimen_5_dp"
android:orientation="vertical"
android:paddingTop="10dp"
app:visibleGone="#{isMultiSelect}" />
<EditText
android:id="#+id/et_sub_obj"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dimen_5_dp"
android:fontFamily="sans-serif"
android:gravity="left"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="3000"
android:overScrollMode="always"
android:padding="5dp"
app:visibleGone="#{isSubjectiveObjectiveTrueOption}"
tools:text="enter text here.." />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/objective_remarks_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
app:visibleGone="#{isObjectiveWithRemarks}"
>
<RadioGroup
android:id="#+id/rg_objective_with_remarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dimen_5_dp"
android:clickable="#{isViewMode}"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:listToRadioGroup="#{optionDataWithAnswer}" />
<Switch
android:id="#+id/toggle_objective_remarks_textbox"
android:layout_width="0dp"
android:paddingTop="2dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/add_remarks"
android:paddingEnd="#dimen/dimen_10_dp"
android:paddingStart="#dimen/dimen_10_dp"
android:textSize="17sp"
android:fontFamily="#font/work_sans"
android:switchPadding="#dimen/dimen_15_dp"
android:gravity="end"
android:textOn="#string/on"
android:textOff="#string/off"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rg_objective_with_remarks"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideInset"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toggle_objective_remarks_textbox"
>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/objective_remarks_field_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="#string/enter_remarks"
app:counterMaxLength="200"
app:counterEnabled="true"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toggle_objective_remarks_textbox">
<EditText
android:id="#+id/objective_remarks_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/dimen_15_dp"
android:layout_marginEnd="#dimen/dimen_15_dp"
android:minHeight="100dp"
android:minLines="3"
android:autofillHints="Enter Remarks"
android:background="#drawable/desc_answer_bg"
android:enabled="#{isViewMode}"
android:fontFamily="#font/work_sans"
android:gravity="top|start"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textShortMessage"
android:maxLength="200"
android:overScrollMode="always"
android:padding="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#202124"
android:textSize="21sp" />
</com.google.android.material.textfield.TextInputLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
app:visibleGone="#{isMultiSelectWithRemarks}"
>
<LinearLayout
android:id="#+id/layout_multiselect_remarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/dimen_5_dp"
android:orientation="vertical"
android:paddingTop="10dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Switch
android:id="#+id/toggle_multiselect_remarks_textbox"
android:layout_width="0dp"
android:paddingTop="2dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/add_remarks"
android:textSize="17sp"
android:fontFamily="#font/work_sans"
android:switchPadding="#dimen/dimen_15_dp"
android:gravity="end"
android:paddingEnd="#dimen/dimen_10_dp"
android:paddingStart="#dimen/dimen_10_dp"
android:textOn="#string/on"
android:textOff="#string/off"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/layout_multiselect_remarks"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/multiselect_remarks_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/enter_remarks"
app:counterEnabled="true"
app:counterMaxLength="200"
android:visibility="gone"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toggle_multiselect_remarks_textbox"
>
<EditText
android:id="#+id/multiselect_remarks_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/dimen_15_dp"
android:layout_marginEnd="#dimen/dimen_15_dp"
android:padding="10dp"
android:minHeight="100dp"
android:minLines="3"
android:background="#drawable/desc_answer_bg"
android:enabled="#{isViewMode}"
android:overScrollMode="always"
android:fontFamily="#font/work_sans"
android:gravity="top|start"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textShortMessage"
android:textAppearance="?android:attr/textAppearanceMedium"
android:maxLength="200"
android:textColor="#202124"
android:textSize="21sp"
android:autofillHints="Enter Remarks" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/short_answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/dimen_10_dp"
android:hint="#string/enter_short_answer"
android:orientation="vertical"
android:textColor="#000"
app:visibleGone="#{isShortAnswer}"
>
<EditText
android:id="#+id/short_answer_et_question"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="#dimen/dimen_15_dp"
android:layout_marginEnd="#dimen/dimen_15_dp"
android:enabled="#{isViewMode}"
android:gravity="top|start"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLength="1000"
android:background="#drawable/desc_answer_bg"
android:fontFamily="#font/work_sans"
android:textColor="#202124"
android:textSize="21sp"
android:overScrollMode="always"
android:padding="#dimen/dimen_10_dp"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:singleLine="false"
android:text="#={shortAnswerText}"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</com.google.android.material.textfield.TextInputLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="#dimen/dimen_5_dp"
app:visibleGone="#{isDate}"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="10dp"
android:paddingVertical="20dp"
android:layout_marginHorizontal="#dimen/dimen_15_dp"
android:orientation="horizontal"
android:background="#drawable/calendar_bg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/date_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="28dp"
android:hint="#string/choose_a_date"
android:fontFamily="#font/work_sans"
android:text="#={DateText}"
android:textSize="21sp"
android:textColor="#000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/calendar_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/calendar_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_marginStart="#dimen/dimen_15_dp"
android:layout_marginEnd="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_baseline_calendar_today_24"
android:focusable="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="8dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
app:visibleGone="#{isMarksWithRemarks}">
<LinearLayout
android:id="#+id/marks_with_remarks_linearLayout"
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_marginStart="34dp"
android:background="#drawable/bg_border_edittext"
android:gravity="center"
android:textColor="#000"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="#+id/et_marks_remarks"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/dimen_5_dp"
android:layout_marginEnd="#dimen/dimen_5_dp"
android:background="#drawable/bg_border_edittext"
android:fontFamily="sans-serif"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLength="4"
android:overScrollMode="always"
android:padding="3dp"
android:textColor="#000"
android:textSize="29sp" />
</LinearLayout>
<TextView
android:id="#+id/tv_total_marks_remarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginEnd="24dp"
android:layout_marginBottom="18dp"
android:fontFamily="#font/work_sans"
android:gravity="end|right"
android:padding="#dimen/dimen_10_dp"
android:text="#{`Out of ` + totalMarks}"
android:textColor="#4D89EB"
android:textSize="17sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/marks_text_input_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:visibleGone="#{isMarksWithRemarks}"
tools:text="Outof 10" />
<Switch
android:id="#+id/toggle_marks_remarks_textbox"
android:layout_width="0dp"
android:paddingTop="2dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/add_remarks"
android:textSize="17sp"
android:paddingEnd="#dimen/dimen_10_dp"
android:paddingStart="#dimen/dimen_10_dp"
android:gravity="end"
android:fontFamily="#font/work_sans"
android:switchPadding="#dimen/dimen_15_dp"
android:textOn="#string/on"
android:textOff="#string/off"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/marks_with_remarks_linearLayout"
</LinearLayout>
</androidx.cardview.widget.CardView>
Fragment class
Java
Objects.requireNonNull(getActivity()).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
also added attributes in manifest file
<activity android:name=".view.AssessmentActivity"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
/>
Here I have two solutions. They might be helpful for you.
android:windowSoftInputMode="adjustResize|stateHidden"
or
Simply adding this to the parent layout:
android:fitsSystemWindows="true"

RecyclerView not scrolling inside NestedScrollView

I'm designing a complex UI that has a NestedScrollView as a parent and inside it, there is a RecyclerView. Now the problem is that I'm not able to scroll the items inside the RecyclerView.
Things I've tried
Replacing ScrollView with NestedScrollView
Enabling android:fillViewport="true"
Disabling NestedScrolling of RecyclerView
<?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=".screens.StudentPreview">
<androidx.cardview.widget.CardView
android:id="#+id/toolbarCV"
android:layout_width="match_parent"
android:layout_height="130dp"
android:translationY="-45dp"
app:cardCornerRadius="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1641A2">
<ImageView
android:id="#+id/menuIV"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_gravity="center"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:src="#drawable/ic_home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.7" />
<TextView
android:id="#+id/featureName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="#font/poppins_light"
android:text="Student Preview"
android:textColor="#fff"
android:textSize="22sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.75" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.core.widget.NestedScrollView
android:id="#+id/studentPreviewNSV"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="90dp"
android:fillViewport="true"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="#+id/avatarCV"
android:layout_width="60dp"
android:layout_height="60dp"
app:cardBackgroundColor="#color/colorPrimaryDark"
app:cardCornerRadius="40dp"
app:cardElevation="0dp"
app:layout_constraintBottom_toBottomOf="#+id/studentDetailsCL"
app:layout_constraintEnd_toStartOf="#+id/studentDetailsCL"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/studentDetailsCL">
<ImageView
android:id="#+id/avatarIV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:visibility="gone"
tools:src="#drawable/avatar_sample" />
<TextView
android:id="#+id/nameInitialTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/montserrat"
android:textColor="#FFF"
android:textSize="24sp"
android:textStyle="bold"
android:visibility="gone"
tools:text="AK"
tools:visibility="visible" />
</androidx.cardview.widget.CardView>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/studentDetailsCL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/avatarCV"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/studentNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/montserrat"
android:textColor="#000"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Akrit Khanna" />
<TextView
android:id="#+id/classNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/montserrat"
android:textColor="#000"
android:textSize="15sp"
app:layout_constraintStart_toStartOf="#+id/studentNameTV"
app:layout_constraintTop_toBottomOf="#+id/studentNameTV"
tools:text="Class 8th A" />
<TextView
android:id="#+id/lastLoggedTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:fontFamily="#font/raleway"
android:textColor="#000"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/classNameTV"
app:layout_constraintTop_toBottomOf="#+id/classNameTV"
tools:text="Last Logged: 30-01-2020" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView
android:id="#+id/classEnrollCV"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
app:cardBackgroundColor="#F5F5F5"
app:cardCornerRadius="18dp"
app:cardElevation="3dp"
app:layout_constraintEnd_toStartOf="#+id/courseEnrollCV"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/detailsGL">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/classEnrollCountTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/raleway"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/classEnrollTVContainerFL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
<FrameLayout
android:id="#+id/classEnrollTVContainerFL"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#D0D9EC"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/raleway"
android:text="Classes Enrolled"
android:textColor="#1641A2"
android:textSize="18sp" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/courseEnrollCV"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:cardBackgroundColor="#F5F5F5"
app:cardCornerRadius="18dp"
app:cardElevation="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/classEnrollCV"
app:layout_constraintTop_toTopOf="#+id/detailsGL">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/courseEnrollCountTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/raleway"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/courseEnrollTVContainerFL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
<FrameLayout
android:id="#+id/courseEnrollTVContainerFL"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#D0D9EC"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/raleway"
android:text="Courses Enrolled"
android:textColor="#1641A2"
android:textSize="18sp" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/detailsGL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="90dp" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/reportCL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#F5F5F5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/classEnrollCV">
<Spinner
android:id="#+id/classOrTermSpinner"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toStartOf="#+id/courseSpinner"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="#+id/courseSpinner"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/classOrTermSpinner"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/reportRV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/courseSpinner" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Use a NestedScrolView and add this to your RecyclerView:
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setHasFixedSize(false);
Or this to the XML:
android:nestedScrollingEnabled="false"
Also it might help to add orientation to the recyclerView:
android:orientation="vertical"
Wrap all the views present inside NestedScrollView into a RelativeLayout. For ex,
<androidx.core.widget.NestedScrollView
android:id="#+id/studentPreviewNSV"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="90dp"
android:fillViewport="true"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- your remaining code -->
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
I managed to fix this problem by adding android:layout_marginBottom="100dp"
I think this was happening because I gave android:layout_marginTop="90dp" to my NestedScrollView and due to that RecyclerView was assuming that all the items are visible on the screen so there is no need for scrolling. (Correct me if I'm wrong)
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/reportRV"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/courseSpinner"
tools:listitem="#layout/report_list_layout"
android:orientation="vertical"
android:layout_marginBottom="100dp"/>

Android Studio - App doesn't cover Emulator

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>

How to make an edittext fit between two buttons?

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

Error in using Recycler View and Scroll View together?

I have been facing issue using Recycler View and Scroll View together in the same bottom navigation activity in different tabs. I am hiding one of the view by using Visibility Gone in the java file.
I tried many solutions but nothing worked till now so I am posting here if someone can help me figure it out.
<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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cartoonswikipedia.www.familyconnect.Main2Activity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:layout_marginBottom="60dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/postrecycler"
android:layout_width="368dp"
android:layout_height="312dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimaryDark">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/toolbar_subtitle"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:paddingLeft="10dp"
android:text="#string/app_name"
android:textColor="#FFFFFF"
android:textSize="30dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/profileimagee45"
android:layout_width="69dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right"
android:clickable="true"
android:onClick="hi"
android:padding="12dp"
app:srcCompat="#drawable/c" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_marginTop="60dp"
android:layout_marginBottom="60dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<TableLayout
android:id="#+id/abc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TextView
android:id="#+id/editemail"
android:layout_width="262dp"
android:layout_height="37dp"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.113" />
<ImageView
android:id="#+id/profileimage"
android:layout_width="87dp"
android:layout_height="88dp"
android:adjustViewBounds="false"
android:cropToPadding="false"
android:onClick="proimg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.167"
android:clickable="false"/>
<EditText
android:id="#+id/editname"
android:layout_width="262dp"
android:layout_height="50dp"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.338" />
<LinearLayout
android:id="#+id/abcdef"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/children"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Children"
android:textSize="25dp"/>
<ImageView
android:id="#+id/adddd"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
<EditText
android:id="#+id/editheight"
android:layout_width="262dp"
android:layout_height="50dp"
android:ems="10"
android:hint="Height in CM"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.338" />
<EditText
android:id="#+id/editweight"
android:layout_width="262dp"
android:layout_height="50dp"
android:ems="10"
android:hint="Weight in KG"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.338" />
<RelativeLayout>
<TextView
android:id="#+id/blood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:text="Blood Group"
android:textSize="25dp" />
</RelativeLayout>
<RelativeLayout>
<TextView
android:id="#+id/religion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:text="Religion"
android:textSize="25dp" />
</RelativeLayout>
<Button
android:id="#+id/editprofile"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:background="#000000"
android:onClick="edit"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Save Profile"
android:textColor="#ffffff" />
<Button
android:id="#+id/logout"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:background="#000000"
android:onClick="logout"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Log Out"
android:textColor="#ffffff"
android:textSize="15dp"
android:textStyle="bold"/>
</TableLayout>
</ScrollView>
<ProgressBar
android:id="#+id/empty_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.464" />
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_marginTop="60dp"
android:layout_marginBottom="60dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:theme="#style/AppTheme"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/navigation" />

Categories

Resources