I am a newbie to android. I have Recyclerview implemented inside NestedScrollView. When I press next everything works fine, but when I return to the previous item it just wraps itself.
I have tried everything possible to make it work.
Following is the code.
For the Next & previous question, on pressing respective the following code executes
QuizAttemptFragment.xml.
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true"
tools:context=".view.fragments.QuizAttemptFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:descendantFocusability="beforeDescendants"
android:layout_width="match_parent"
android:id="#+id/clQuiz"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvFeedBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:fontFamily="#font/nunito_regular"
tools:text="Feedback"
android:gravity="center"
android:drawablePadding="4dp"
android:drawableStart="#drawable/ic_comment_black"
android:drawableTint="#color/blackColor"
android:textSize="14sp"
android:visibility="visible"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/tvAssignmentStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginTop="15dp"
android:fontFamily="#font/nunito_regular"
tools:text="Marked"
android:textSize="14sp"
android:textAllCaps="true"
android:visibility="invisible"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvQuestionNum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="47dp"
android:layout_marginEnd="16dp"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
tools:listitem="#layout/layout_num"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvQuestionDet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:visibility="gone"
android:layout_marginEnd="16dp"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="#+id/pbFragmentListLoading"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="56dp"
android:visibility="gone"
android:indeterminate="true"
android:indeterminateTint="#color/yellowThemeColor"
android:indeterminateTintMode="src_atop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.526"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tvDur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="93dp"
android:drawableStart="#drawable/ic_clock_blck"
android:drawablePadding="10dp"
android:fontFamily="#font/nunito_bold"
android:gravity="center_vertical"
android:text="DD:HH:MM"
android:textColor="#000000"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.089"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteY="98dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvQuestionNew"
android:nestedScrollingEnabled="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:minHeight="300dp"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="#id/rlNav"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvDur"
app:layout_constraintVertical_bias="0.0"
tools:listitem="#layout/user_question" />
<RelativeLayout
android:id="#+id/rlNav"
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/tvBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:layout_alignParentStart="true"
android:drawablePadding="10dp"
android:drawableTint="#color/blackColor"
android:fontFamily="#font/nunito_regular"
android:gravity="center"
android:textAllCaps="true"
android:text="Previous"
android:textColor="#color/blackColor"
android:textSize="16sp"
android:visibility="invisible" />
<ImageButton
android:background="#android:color/transparent"
android:id="#+id/ibFlag"
android:visibility="visible"
android:layout_centerInParent="true"
android:src="#drawable/ic_flag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tvNext"
android:layout_marginEnd="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:layout_alignParentEnd="true"
android:drawablePadding="10dp"
android:drawableTint="#color/blackColor"
android:fontFamily="#font/nunito_regular"
android:gravity="center"
android:textAllCaps="true"
android:text="Next"
android:textColor="#color/blackColor"
android:textSize="16sp"
android:visibility="visible" />
<androidx.cardview.widget.CardView
android:id="#+id/cvSubmit"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginEnd="5dp"
android:minWidth="80dp"
android:visibility="gone"
android:clickable="true"
android:padding="5dp"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:layout_alignParentEnd="true"
app:cardCornerRadius="4dp">
<LinearLayout
android:id="#+id/llCard"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvBtnCreateAssignmentSubmit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#584056"
android:clickable="true"
android:fontFamily="#font/nunito_regular"
android:text="Submit"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#color/whiteColor"
android:textSize="16sp"
android:visibility="visible" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
layout_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:layout_marginBottom="5dp"
android:background="#fcfbfc"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/lblPoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="4dp"
android:fontFamily="#font/nunito_light"
android:textColor="#color/blackColor"
android:textSize="12sp"
tools:text="10 Points" />
<RelativeLayout
android:id="#+id/rlheader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:visibility="visible"
>
<TextView
android:id="#+id/lblques"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="4dp"
android:fontFamily="#font/nunito_light"
android:textColor="#color/blackColor"
android:textSize="14sp"
tools:text="15." />
<TextView
android:id="#+id/tvQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginEnd="10dp"
android:fontFamily="#font/nunito_regular"
android:gravity="center_vertical"
android:layout_centerInParent="true"
android:layout_toStartOf="#+id/edPoint"
android:minLines="2"
tools:text="Who from the following is responsible for this question"
android:textSize="16sp"
android:scrollbars="vertical"
android:textColor="#color/blackColor" />
<TextView
android:id="#+id/tvPoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="4dp"
android:fontFamily="#font/nunito_light"
android:gravity="center"
android:visibility="gone"
android:minLines="1"
android:textColor="#color/blackColor"
android:textSize="16sp"
tools:text="/10" />
<EditText
android:id="#+id/edPoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:visibility="gone"
android:layout_centerInParent="true"
android:fontFamily="#font/nunito_light"
android:gravity="center"
android:minLines="1"
android:inputType="number"
tools:text="100"
android:imeOptions="actionDone"
android:layout_toStartOf="#+id/tvPoint"
android:textSize="14sp"
android:textColor="#color/blackColor" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlAnswer"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:elevation="5dp"
android:background="#drawable/shape_square"
android:layout_marginBottom="20dp"
android:minHeight="100dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:padding="10dp"
android:id="#+id/edAnswer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/nunito_regular"
android:gravity="top"
tools:text="assfadasffdsdfddfd"
android:layout_gravity="top"
android:textSize="16sp"
android:scrollbars="vertical"
android:textColor="#color/blackColor" />
</RelativeLayout>
<LinearLayout
android:id="#+id/llOptions"
android:orientation="vertical"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:clickable="false"
android:id="#+id/llOpt1"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/rbOpt1"
android:layout_marginEnd="#dimen/_10sdp"
android:layout_width="wrap_content"
android:clickable="false"
android:buttonTint="#color/darkGreyColor"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:clickable="false"
android:id="#+id/llOpt2"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/rbOpt2"
android:layout_marginEnd="#dimen/_10sdp"
android:layout_width="wrap_content"
android:clickable="false"
android:buttonTint="#color/darkGreyColor"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="#+id/llOpt3"
android:clickable="false"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/rbOpt3"
android:layout_marginEnd="#dimen/_10sdp"
android:layout_width="wrap_content"
android:clickable="false"
android:buttonTint="#color/darkGreyColor"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="#+id/llOpt4"
android:clickable="false"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/rbOpt4"
android:layout_marginEnd="#dimen/_10sdp"
android:layout_width="wrap_content"
android:clickable="false"
android:buttonTint="#color/darkGreyColor"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<androidx.cardview.widget.CardView
app:cardCornerRadius="8dp"
android:id="#+id/cvDocPreview"
android:visibility="visible"
android:layout_marginTop="4dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/llCreateAssignmentParent1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/whiteColor"
android:gravity="center_vertical"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="#+id/cardImage"
app:cardElevation="0dp"
android:layout_width="#dimen/_60sdp"
android:layout_height="#dimen/_40sdp">
<ImageView
android:id="#+id/ivPreviewItem"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="match_parent"
android:minHeight="60dp"
android:src="#drawable/ic_file_black"
android:background="#color/thumbnail_background"
android:adjustViewBounds="true"
android:scaleType="centerInside"/>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_toRightOf="#+id/cardImage"
android:id="#+id/llFileUpload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="40dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/tvFileNameItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="0.02"
android:ellipsize="end"
android:layout_marginEnd="5dp"
android:maxLines="1"
android:fontFamily="#font/nunito_bold"
android:lineSpacingExtra="0sp"
android:textColor="#000000"
android:textSize="14sp"
tools:text="Filename.ext" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvFileType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.02"
android:textColor="#000000"
android:textSize="12sp"
android:maxLines="1"
android:ellipsize="end"
android:layout_marginEnd="4dp"
android:fontFamily="#font/nunito_regular"
tools:text="File Type" />
<View
android:id="#+id/viewDivide"
android:layout_gravity="center"
android:background="#color/black_half"
android:layout_width="1dp"
android:layout_height="#dimen/_10sdp"/>
<TextView
android:id="#+id/tvFileSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.02"
android:textColor="#000000"
android:textSize="12sp"
android:maxLines="1"
android:ellipsize="end"
android:layout_marginStart="4dp"
android:fontFamily="#font/nunito_regular"
android:text="24 mb" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:padding="7dp"
android:layout_centerInParent="true"
android:layout_alignParentEnd="true"
android:visibility="visible"
android:id="#+id/ibDownloadItem"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="4dp"
android:background="#color/whiteColor"
android:tint="#color/blackColor"
android:src="#android:drawable/stat_sys_download" />
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/tvNotAttempted"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="4dp"
android:layout_gravity="center"
android:visibility="gone"
android:fontFamily="#font/nunito_light"
android:gravity="center"
android:text="Question not attempted"
android:minLines="1"
android:textColor="#color/redWarningColor"
android:textSize="16sp" />
<TextView
android:id="#+id/tvMandatory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_gravity="center"
android:visibility="gone"
android:fontFamily="#font/nunito_light"
android:gravity="center"
android:text="Mandatory Question*"
android:minLines="1"
android:textColor="#color/redWarningColor"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
Before Pressing Next
Returning to the previous item it just wraps views
Please help, I am stuck for 2 weeks
Related
I have this RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="vertical"
tools:context=".ui.StoreVisitActivity">
<ScrollView
android:id="#+id/scrollable"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/_8sdp"
android:layout_marginRight="#dimen/_8sdp"
android:orientation="vertical">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:orientation="horizontal">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:layout_width="#dimen/_55sdp"
android:layout_height="#dimen/_55sdp"
android:src="#drawable/person" />
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_4sdp"
android:text="Paul Phoenix"
android:textColor="#color/main_blue"
android:textSize="#dimen/_14sdp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_4sdp"
android:text="PX2350"
android:textColor="#color/main_blue"
android:textSize="#dimen/_10sdp"
android:textStyle="bold" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
<ImageView
android:layout_width="#dimen/_60sdp"
android:layout_height="#dimen/_30sdp"
android:layout_gravity="center"
android:src="#drawable/company_logo" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:layout_marginBottom="#dimen/_2sdp"
android:background="#drawable/bg_border_radius"
android:orientation="vertical"
android:padding="#dimen/_16sdp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/_20sdp"
android:layout_marginTop="#dimen/_4sdp"
android:background="#color/main_blue"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:gravity="center"
android:maxLines="1"
android:text="Day, Date"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/_7sdp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:background="#color/black_5"
android:orientation="horizontal"
android:padding="#dimen/_8sdp">
<TextView
android:id="#+id/txtTanggal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:gravity="center"
android:maxLines="1"
android:text="0"
android:textAllCaps="true"
android:textSize="#dimen/_7sdp" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/input_search"
android:layout_width="match_parent"
android:layout_height="#dimen/_25sdp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/rectangle_input"
android:hint="Search Name Outlet"
android:inputType="text"
android:paddingHorizontal="#dimen/_10sdp"
android:textSize="#dimen/_7sdp" />
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardBackgroundColor="#color/blue_1"
app:cardCornerRadius="#dimen/_8sdp"
app:cardUseCompatPadding="true">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/btnSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/_8sdp">
<ImageView
android:layout_width="#dimen/_15sdp"
android:layout_height="#dimen/_15sdp"
android:src="#drawable/ic_search" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/_20sdp"
android:background="#color/main_blue"
android:orientation="horizontal"
android:padding="#dimen/_4sdp">
<TextView
android:id="#+id/txtNo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="center"
android:maxLines="1"
android:text="No"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/_7sdp"
android:textStyle="normal" />
<TextView
android:id="#+id/txtQtyInbound"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:maxLines="1"
android:text="Code"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/_7sdp" />
<TextView
android:id="#+id/txtDesc"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:gravity="center"
android:maxLines="1"
android:text="Store Name"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/_7sdp" />
<TextView
android:id="#+id/txtQtyScan"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:maxLines="1"
android:text="Address"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/_7sdp" />
<TextView
android:id="#+id/txtSelect"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:maxLines="1"
android:text="Select"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/_7sdp" />
</LinearLayout>
<cz.kinst.jakub.view.SimpleStatefulLayout
android:id="#+id/stateful"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listPlanJourney"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="4" />
</cz.kinst.jakub.view.SimpleStatefulLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/llButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="#dimen/_8sdp"
android:layout_marginTop="#dimen/_16sdp"
android:layout_marginRight="#dimen/_8sdp"
android:layout_marginBottom="#dimen/_10sdp"
android:orientation="horizontal">
<Button
android:id="#+id/btnExit"
android:layout_width="match_parent"
android:layout_height="#dimen/_25sdp"
android:layout_weight="1"
android:background="#drawable/rectangle_button"
android:text="Exit"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="#dimen/_7sdp" />
<Button
android:id="#+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="#dimen/_25sdp"
android:layout_marginLeft="#dimen/_4sdp"
android:layout_weight="1"
android:background="#drawable/rectangle_button"
android:text="Start Visit"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="#dimen/_7sdp" />
</androidx.appcompat.widget.LinearLayoutCompat>
</RelativeLayout>
The RecyclerView may contains lots of items (say > 80), that why I put it inside a ScrollView. And I want the Buttons to stay permanent on the bottom of the screen, that's why I use android:layout_alignParentBottom="true". But when I run in, the result is not what I expect. Turns out the Buttons are actually "floating" on top of the ScrollView, like this:
What I want is the LinearLayout containing the Buttons stuck at the buttom, and the rest above it are fully occupied by the ScrollView. How to fix this?
I recommended you use ConstraintLayout and avoid nested layout as much as you can. I have modified your code as little as possible just to fit your needs like below(replace margin/padding back to your desire):
<?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">
<LinearLayout
android:id="#+id/layout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:src="#drawable/ic_notification" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="Paul Phoenix"
android:textColor="#0000FF"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="PX2350"
android:textColor="#0000FF"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="60dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:src="#drawable/ic_notification" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="2dp"
android:background="#drawable/bg_pb"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintTop_toBottomOf="#id/layout_1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginTop="4dp"
android:background="#0000FF"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:gravity="center"
android:maxLines="1"
android:text="Day, Date"
android:textAllCaps="true"
android:textColor="#FFFFFF"
android:textSize="7dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:background="#000000"
android:orientation="horizontal"
android:padding="8dp">
<TextView
android:id="#+id/txtTanggal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:gravity="center"
android:maxLines="1"
android:text="0"
android:textAllCaps="true"
android:textSize="7dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/layout_2">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/input_search"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/ic_notification"
android:hint="Search Name Outlet"
android:inputType="text"
android:paddingHorizontal="10dp"
android:textSize="7dp" />
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardBackgroundColor="#0000AA"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:id="#+id/btnSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_notification" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_header"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#0000FF"
android:orientation="horizontal"
android:padding="4dp"
app:layout_constraintTop_toBottomOf="#id/layout_search">
<TextView
android:id="#+id/txtNo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="center"
android:maxLines="1"
android:text="No"
android:textAllCaps="true"
android:textColor="#FFFFFF"
android:textSize="7dp"
android:textStyle="normal" />
<TextView
android:id="#+id/txtQtyInbound"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:maxLines="1"
android:text="Code"
android:textAllCaps="true"
android:textColor="#FFFFFF"
android:textSize="7dp" />
<TextView
android:id="#+id/txtDesc"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:gravity="center"
android:maxLines="1"
android:text="Store Name"
android:textAllCaps="true"
android:textColor="#FFFFFF"
android:textSize="7dp" />
<TextView
android:id="#+id/txtQtyScan"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:maxLines="1"
android:text="Address"
android:textAllCaps="true"
android:textColor="#FFFFFF"
android:textSize="7dp" />
<TextView
android:id="#+id/txtSelect"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:maxLines="1"
android:text="Select"
android:textAllCaps="true"
android:textColor="#FFFFFF"
android:textSize="7dp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listPlanJourney"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/llButtons"
app:layout_constraintTop_toBottomOf="#id/layout_header"
tools:itemCount="4" />
<LinearLayout
android:id="#+id/llButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
<Button
android:id="#+id/btnExit"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_weight="1"
android:background="#drawable/bg_pb"
android:text="Exit"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="7dp" />
<Button
android:id="#+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:background="#drawable/bg_pb"
android:text="Start Visit"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="7dp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Well, I made ScrollView and inside it, I put one LinearLayout. Inside that LinearLayout, I put multiple LinearLayouts and it does not show any error. Also, as you can see image, you can see their shape and that they are constrained. But I cannot see source/background of the ImageViews and TextViews neither within Android Studio nor when I buil app, why?
img1
Here is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background1_1"
tools:context=".MainActivity">
<ImageView
android:id="#+id/stol"
android:layout_width="0dp"
android:layout_height="210dp"
android:layout_marginTop="8dp"
android:background="#drawable/stol"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/naslov" />
<TextView
android:id="#+id/naslov"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="#font/bangers"
android:text="POKER CHANCE CALCULATOR"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="36sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/table_cards"
android:layout_width="0dp"
android:layout_height="58dp"
android:layout_marginStart="50dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="50dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="#+id/stol"
app:layout_constraintEnd_toEndOf="#+id/stol"
app:layout_constraintStart_toStartOf="#+id/stol"
app:layout_constraintTop_toTopOf="#+id/stol">
<ImageView
android:id="#+id/table_card1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="#drawable/backside" />
<ImageView
android:id="#+id/table_card2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="#drawable/backside" />
<ImageView
android:id="#+id/table_card3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="#drawable/backside" />
<ImageView
android:id="#+id/table_card4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:background="#drawable/backside" />
<ImageView
android:id="#+id/table_card5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:background="#drawable/backside" />
</LinearLayout>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/stol">
<!--
Početak vanjskog sloja!
-->
<LinearLayout
android:id="#+id/linear_vanjski_sloj"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
android:weightSum="1"
app:layout_constraintBottom_toBottomOf="#+id/scroll_view"
app:layout_constraintEnd_toEndOf="#+id/scroll_view"
app:layout_constraintStart_toStartOf="#+id/scroll_view"
app:layout_constraintTop_toTopOf="#+id/scroll_view">
<LinearLayout
android:id="#+id/linear_first_row"
android:layout_width="410dp"
android:layout_height="194dp"
android:layout_marginTop="32dp"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/stol">
<LinearLayout
android:id="#+id/linear_player1"
android:layout_width="159dp"
android:layout_height="180dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:background="#drawable/okvir"
android:orientation="vertical"
android:weightSum="1"
tools:layout_editor_absoluteX="50dp"
tools:layout_editor_absoluteY="338dp">
<TextView
android:id="#+id/player1_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elegantTextHeight="true"
android:fontFamily="#font/bangers"
android:gravity="center"
android:text="PLAYER 1"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="24sp" />
<LinearLayout
android:id="#+id/linear_player1_2"
android:layout_width="144dp"
android:layout_height="103dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/player2_card1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_weight="1"
android:src="#drawable/backside" />
<ImageView
android:id="#+id/player2_card2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_weight="1"
android:src="#drawable/backside" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear2_stats"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/win_stats2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="WIN\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/draw_stats2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="TIE\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/lose_stats2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="LOSE\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_player2"
android:layout_width="159dp"
android:layout_height="180dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:background="#drawable/okvir"
android:orientation="vertical"
android:weightSum="1"
tools:layout_editor_absoluteX="240dp"
tools:layout_editor_absoluteY="305dp">
<TextView
android:id="#+id/player2_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elegantTextHeight="true"
android:fontFamily="#font/bangers"
android:gravity="center"
android:text="PLAYER 2"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="24sp" />
<LinearLayout
android:id="#+id/player2_2"
android:layout_width="144dp"
android:layout_height="103dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/player1_card1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_weight="1"
android:src="#drawable/backside" />
<ImageView
android:id="#+id/player1_card2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_weight="1"
android:src="#drawable/backside" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1_stats"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/win_stats1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="WIN\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/draw_stats1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="TIE\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/lose_stats1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="LOSE\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_second_row"
android:layout_width="410dp"
android:layout_height="194dp"
android:layout_marginTop="32dp"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/stol">
<LinearLayout
android:id="#+id/linear_player3"
android:layout_width="159dp"
android:layout_height="180dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:background="#drawable/okvir"
android:orientation="vertical"
android:weightSum="1"
tools:layout_editor_absoluteX="50dp"
tools:layout_editor_absoluteY="338dp">
<TextView
android:id="#+id/player3_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elegantTextHeight="true"
android:fontFamily="#font/bangers"
android:gravity="center"
android:text="PLAYER 3"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="24sp" />
<LinearLayout
android:id="#+id/linear_player2_1"
android:layout_width="144dp"
android:layout_height="103dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/player3_card1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_weight="1"
android:src="#drawable/backside" />
<ImageView
android:id="#+id/player3_card2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_weight="1"
android:src="#drawable/backside" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear3_stats"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/win_stats3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="WIN\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/draw_stats3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="TIE\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/lose_stats3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="LOSE\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_player4"
android:layout_width="159dp"
android:layout_height="180dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:background="#drawable/okvir"
android:orientation="vertical"
android:weightSum="1"
tools:layout_editor_absoluteX="240dp"
tools:layout_editor_absoluteY="305dp">
<TextView
android:id="#+id/player4_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elegantTextHeight="true"
android:fontFamily="#font/bangers"
android:gravity="center"
android:text="PLAYER 4"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="24sp" />
<LinearLayout
android:id="#+id/player4_2"
android:layout_width="144dp"
android:layout_height="103dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/player4_card1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_weight="1"
android:src="#drawable/backside" />
<ImageView
android:id="#+id/player4_card2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
android:layout_weight="1"
android:src="#drawable/backside" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear4_stats"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/win_stats4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="WIN\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/draw_stats4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="TIE\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<TextView
android:id="#+id/lose_stats4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="LOSE\n00,00%"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!--
Kraj vanjskog sloja!
-->
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Try to use a NestedScrollView instead of the ScrollView ...that usually this is only required for CoordinatorLayout, but it eventually may also be the case within a ConstraintLayout.
I need to make a list in my NestedScrollView but showing only first element. I tried with android:fillViewport="true" but hothing happened. I know that ListView has scrollable incorporated in itself.
my xml :
<layout >
<data>
<variable
name="home"
type="com.nswd.successplan.ui.fragments.homeFragment.HomeViewModel" />
</data>
<androidx.core.widget.NestedScrollView
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="#f0f4f7"
android:fillViewport="true"
tools:context=".ui.fragments.homeFragment.HomeFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="#f0f4f7">
<TextView
android:id="#+id/dashboard_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:gravity="center"
android:text="Dashboard"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/first_row_LL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
<LinearLayout
android:id="#+id/first_row_LL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/date_time_LL"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/dashboard_TV">
<LinearLayout
android:id="#+id/my_plan_LV"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:background="#0f5acf"
android:onClick="#{home::updateMyPlanOnClick}"
android:orientation="vertical"
android:padding="2dp">
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:src="#drawable/ic_assignment" />
<TextView
android:id="#+id/home_fragment_update_my_plan_TV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Update My Plan"
android:textColor="#ffffff"
android:textSize="11sp"
tools:ignore="SmallSp" />
</LinearLayout>
<LinearLayout
android:id="#+id/update_my_budget_LV"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:background="#4d88ff"
android:baselineAligned="false"
android:onClick="#{home::updateMyBudgetOnCLick}"
android:orientation="vertical"
android:padding="2dp">
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:src="#drawable/ic_baseline" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Update My Budget"
android:textColor="#ffffff"
android:textSize="10sp"
tools:ignore="SmallSp" />
</LinearLayout>
<LinearLayout
android:id="#+id/contact_advisor_LV"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#0e4087"
android:onClick="#{home::contactAdvisorOnCLick}"
android:orientation="vertical"
android:padding="2dp">
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:src="#drawable/ic_contact_support" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Contact advisor"
android:textColor="#ffffff"
android:textSize="11sp"
tools:ignore="SmallSp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/date_time_LL"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="8dp"
android:background="#884dff"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/second_row_LL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/first_row_LL">
<ImageView
android:id="#+id/date_image_IMG"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_date_range_24" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="00:00"
android:textColor="#ffffff"
android:textSize="24sp" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="29.09.2020"
android:textColor="#ffffff"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/second_row_LL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/pie_chart_expenditures_TV"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/date_time_LL">
<LinearLayout
android:id="#+id/plan_last_update_LV"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Plan Last Updated"
android:textColor="#color/hints_black"
android:textSize="10sp"
tools:ignore="SmallSp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="21"
android:textColor="#3297e9"
android:textSize="28sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Aug 2017"
android:textColor="#a0b4bf"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/until_retirement_LV"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Until Retirement"
android:textColor="#color/hints_black"
android:textSize="10sp"
tools:ignore="SmallSp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="33"
android:textColor="#3297e9"
android:textSize="28sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Years"
android:textColor="#a0b4bf"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/out_of_debt_LV"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Out of Debt Date"
android:textColor="#color/hints_black"
android:textSize="10sp"
tools:ignore="SmallSp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="20"
android:textColor="#3297e9"
android:textSize="28sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Aug 2017"
android:textColor="#a0b4bf"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/pie_chart_expenditures_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#ffffff"
android:gravity="center"
android:text="Monthly Expenditures"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/pie_chart_expenditures_LL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/second_row_LL" />
<LinearLayout
android:id="#+id/pie_chart_expenditures_LL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="#+id/list_view_pie_chart_legend"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/pie_chart_expenditures_TV">
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/pie_chart_reports_home"
android:layout_width="match_parent"
android:layout_height="400dp" />
</LinearLayout>
<ListView
android:id="#+id/list_view_pie_chart_legend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/pie_chart_expenditures_LL"
tools:listitem="#layout/pie_chart_list_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
my item view:
<layout>
<data>
<variable
name="legend"
type="com.nswd.successplan.model.PieChartLegendModel" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:padding="4dp">
<ImageView
android:id="#+id/legend_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_dot_list_item_pie_chart" />
<TextView
android:id="#+id/expenditure"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:text="Debt Payments"
android:textColor="#197ad8" />
<TextView
android:id="#+id/costs_expenditure"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="end"
android:text="7,555" />
</LinearLayout>
</layout>
I'm having a considerable issue that I haven't encountered before. I did what I normally do working with constraints. Not all of my fields will fit on the screen. It shows up fine running on an external tablet. Below is my activitymain. I've also ran it in linear and relative layout. I can Any help would be appreciated.
<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="wrap_content"
android:background="#color/colorBlack"
tools:context=".MainActivity">
<Spinner
android:id="#+id/spCompany"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="468dp"
android:background="#color/colorWhite"
android:gravity="center"
android:spinnerMode="dropdown"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rnumberText" />
<TextView
android:id="#+id/densityText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="#color/colorWhite"
android:text=""
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#id/strainerLabel"
app:layout_constraintTop_toBottomOf="#+id/spCompany" />
<TextView
android:id="#+id/strainerLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text="#string/strainer"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/strainerText"
app:layout_constraintTop_toBottomOf="#+id/spCompany" />
<TextView
android:id="#+id/strainerText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text=""
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/spRatio"
app:layout_constraintTop_toBottomOf="#+id/strainerLabel" />
<Spinner
android:id="#+id/spRatio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toTopOf="#+id/enterweightLabel"
app:layout_constraintTop_toBottomOf="#+id/strainerText" />
<TextView
android:id="#+id/rnumberText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="#color/colorWhite"
android:text=""
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#+id/spCompany"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside" />
<TextView
android:id="#+id/catdensityText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:text=""
app:layout_constraintBottom_toBottomOf="#+id/spRatio"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spRatio" />
<TextView
android:id="#+id/enterweightLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text="#string/enter_weight"
android:textAlignment="center"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/weightInput"
app:layout_constraintTop_toBottomOf="#+id/spRatio" />
<EditText
android:id="#+id/weightInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:autofillHints="Enter Weight"
android:background="#color/colorWhite"
android:clickable="true"
android:ems="10"
android:focusable="true"
android:gravity="center"
android:imeOptions="actionDone"
android:importantForAutofill="yes"
android:inputType="numberDecimal"
android:singleLine="true"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/totalcatLabel"
app:layout_constraintTop_toBottomOf="#+id/enterweightLabel"
tools:targetApi="o" />
<TextView
android:id="#+id/totalcatLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text="#string/total_catalyst"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/totalcatText"
app:layout_constraintTop_toBottomOf="#+id/weightInput" />
<TextView
android:id="#+id/totalcatText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="#color/colorWhite"
android:clickable="false"
android:gravity="center"
android:text=""
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/totalweightLabel"
app:layout_constraintTop_toBottomOf="#+id/totalcatLabel" />
<TextView
android:id="#+id/totalweightLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text="#string/total_weight"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/totalweightText"
app:layout_constraintTop_toBottomOf="#+id/totalcatText" />
<TextView
android:id="#+id/totalweightText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center_horizontal|center_vertical"
android:text=""
android:textSize="60sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/calcButton"
app:layout_constraintTop_toBottomOf="#+id/totalweightLabel" />
<Button
android:id="#+id/calcButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:clickable="true"
android:focusable="true"
android:text="#string/calculate"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/clearButton"
app:layout_constraintTop_toBottomOf="#+id/totalweightText" />
<Button
android:id="#+id/clearButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:clickable="true"
android:focusable="true"
android:text="#string/Clear"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/calcButton" />
</android.support.constraint.ConstraintLayout>
You can put your ConstraintLayout inside a ScrollView
Yeah, your content takes more room than the available then your view overflows the device. Using a ScrollView will solve you problem with short screens.
This is how looks like:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/root">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBlack"
tools:context=".MainActivity">
<Spinner
android:id="#+id/spCompany"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="468dp"
android:background="#color/colorWhite"
android:gravity="center"
android:spinnerMode="dropdown"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rnumberText" />
<TextView
android:id="#+id/densityText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="7dp"
android:background="#color/colorWhite"
android:text=""
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#id/strainerLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spCompany" />
<TextView
android:id="#+id/strainerLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text="#string/strainer"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/strainerText"
app:layout_constraintTop_toBottomOf="#+id/spCompany" />
<TextView
android:id="#+id/strainerText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text=""
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/spRatio"
app:layout_constraintTop_toBottomOf="#+id/strainerLabel" />
<Spinner
android:id="#+id/spRatio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toTopOf="#+id/enterweightLabel"
app:layout_constraintTop_toBottomOf="#+id/strainerText" />
<TextView
android:id="#+id/rnumberText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="#color/colorWhite"
android:text=""
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#+id/spCompany"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside" />
<TextView
android:id="#+id/catdensityText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:text=""
app:layout_constraintBottom_toBottomOf="#+id/spRatio"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spRatio" />
<TextView
android:id="#+id/enterweightLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text="#string/enter_weight"
android:textAlignment="center"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/weightInput"
app:layout_constraintTop_toBottomOf="#+id/spRatio" />
<EditText
android:id="#+id/weightInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:autofillHints="Enter Weight"
android:background="#color/colorWhite"
android:clickable="true"
android:ems="10"
android:focusable="true"
android:gravity="center"
android:imeOptions="actionDone"
android:importantForAutofill="yes"
android:inputType="numberDecimal"
android:singleLine="true"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/totalcatLabel"
app:layout_constraintTop_toBottomOf="#+id/enterweightLabel"
tools:targetApi="o" />
<TextView
android:id="#+id/totalcatLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text="#string/total_catalyst"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/totalcatText"
app:layout_constraintTop_toBottomOf="#+id/weightInput" />
<TextView
android:id="#+id/totalcatText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:background="#color/colorWhite"
android:clickable="false"
android:gravity="center"
android:text=""
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/totalweightLabel"
app:layout_constraintTop_toBottomOf="#+id/totalcatLabel" />
<TextView
android:id="#+id/totalweightLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center"
android:text="#string/total_weight"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/totalweightText"
app:layout_constraintTop_toBottomOf="#+id/totalcatText" />
<TextView
android:id="#+id/totalweightText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:gravity="center_horizontal|center_vertical"
android:text=""
android:textSize="60sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/calcButton"
app:layout_constraintTop_toBottomOf="#+id/totalweightLabel" />
<Button
android:id="#+id/calcButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="#color/colorWhite"
android:clickable="true"
android:focusable="true"
android:text="#string/calculate"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/clearButton"
app:layout_constraintTop_toBottomOf="#+id/totalweightText" />
<Button
android:id="#+id/clearButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:clickable="true"
android:focusable="true"
android:text="#string/Clear"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/calcButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I have a layout with a ScrollView.When I change the picture of an ImageView or Text of TextView, layout refreshes and screen goes to the top.I Think the problem is in ScrollView.
XML file:
<?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">
<ScrollView
android:id="#+id/sv2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFEEEEEE"
android:orientation="vertical"
android:padding="0dp"
tools:context="hamrahyper.rayanpejuhanparse.jamshidiasl.hamrahyper.Main3Activity">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFEEEEEE">
<EditText
android:id="#+id/editText3"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/imageViewx"
android:layout_toRightOf="#+id/imageViewx"
android:background="#color/colorPrimary"
android:ems="10"
android:gravity="center"
android:hint="جستجو در همراهایپر"
android:inputType="textPersonName"
android:textColor="#android:color/background_light"
android:textColorHint="#android:color/background_light"
android:textSize="14sp"
app:layout_constraintEnd_toStartOf="#+id/imageView1"
app:layout_constraintStart_toEndOf="#+id/imageViewx"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignEnd="#+id/editText3"
android:layout_alignRight="#+id/editText3"
android:layout_alignTop="#+id/editText3"
android:background="#color/colorPrimary"
android:padding="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/i1" />
<ImageView
android:id="#+id/imageViewx"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
app:layout_constraintStart_toEndOf="#+id/imageView10"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/icart2" />
<ViewFlipper
android:id="#+id/viewFlipper"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autoStart="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText3">
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:srcCompat="#mipmap/btn1" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:srcCompat="#mipmap/btn2" />
</ViewFlipper>
<TextView
android:id="#+id/textView16"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="right"
android:text="دسته بندی محصولات"
android:textColor="#android:color/background_dark"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/viewFlipper" />
<HorizontalScrollView
android:id="#+id/sc1"
android:layout_width="0dp"
android:layout_height="220dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView16">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:elevation="5dp"
app:cardElevation="5dp">
<RelativeLayout
android:id="#+id/rl1"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:padding="5dp">
<ImageView
android:id="#+id/im1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:srcCompat="#mipmap/icon1" />
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/im1"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/tx1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv1"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/holo_green_dark"
android:textSize="12sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:elevation="5dp"
app:cardElevation="5dp">
<RelativeLayout
android:id="#+id/rl2"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:padding="5dp">
<ImageView
android:id="#+id/im2"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:srcCompat="#mipmap/icon1" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/im2"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/tx2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv2"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/holo_green_dark"
android:textSize="12sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:elevation="5dp"
app:cardElevation="5dp">
<RelativeLayout
android:id="#+id/rl3"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:padding="5dp">
<ImageView
android:id="#+id/im3"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:srcCompat="#mipmap/icon1" />
<TextView
android:id="#+id/tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/im3"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/tx3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv3"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/holo_green_dark"
android:textSize="12sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:elevation="5dp"
app:cardElevation="5dp">
<RelativeLayout
android:id="#+id/rl4"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:padding="5dp">
<ImageView
android:id="#+id/im4"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:srcCompat="#mipmap/icon1" />
<TextView
android:id="#+id/tv4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/im4"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/tx4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv4"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/holo_green_dark"
android:textSize="12sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:elevation="5dp"
app:cardElevation="5dp">
<RelativeLayout
android:id="#+id/rl5"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:padding="5dp">
<ImageView
android:id="#+id/im5"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:srcCompat="#mipmap/icon1" />
<TextView
android:id="#+id/tv5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/im5"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/tx5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv5"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/holo_green_dark"
android:textSize="12sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:elevation="5dp"
app:cardElevation="5dp">
<RelativeLayout
android:id="#+id/rl6"
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:padding="5dp">
<ImageView
android:id="#+id/im6"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:srcCompat="#mipmap/icon1" />
<TextView
android:id="#+id/tv6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/im6"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/tx6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv6"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="..."
android:textColor="#android:color/holo_green_dark"
android:textSize="12sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:layout_constraintTop_toBottomOf="#+id/sc1"
app:srcCompat="#mipmap/btn5"
tools:layout_editor_absoluteX="0dp" />
<TextView
android:id="#+id/textView17"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="right"
android:text="پرفروش ترین محصولات"
android:textColor="#android:color/background_dark"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView6" />
<TextView
android:id="#+id/textView19"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginStart="8dp"
android:layout_marginTop="2dp"
android:background="#mipmap/bdr3"
android:gravity="center"
android:paddingLeft="1dp"
android:paddingTop="1dp"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintStart_toEndOf="#+id/imageView10"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView10"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#color/colorPrimary"
android:paddingBottom="6dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="6dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/menuicon" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</ScrollView>
I think the problem is ScrollView, so I set a focusable property of ScrollView to false but the problem not resolved.What is wrong?
Add this line android:fillViewport="true"
<ScrollView
android:fillViewport="true">
</ScrollView>