I have a xml layout that has a combination of image view, constraint layout and a recycler view. When I scroll the recycler view items, a few of the last items cannot be scrolled to the top fully. These items go beyond the bottom constraint. I have noticed one thing that if my layout consists of only recycler view then this is not a problem. Could this be an issue because my xml layout has an image view, constraint layout as well as a recycler view?
Following is my xml layout, events_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
xmlns:tools="http://schemas.android.com/tools">
<ImageView
android:id="#+id/itemThumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:paddingBottom="16dp"
android:visibility="gone"
android:src="#drawable/social_facebook_teal"
app:layout_constraintDimensionRatio="3:2"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/errorMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/itemThumbnail" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/headerCL"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/itemThumbnail">
<TextView
android:id="#+id/dateHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Date"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="#+id/guidelineNavHeight1">
</TextView>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guidelineNavHeight1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.25" />
<TextView
android:id="#+id/eventHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Event"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/guidelineNavHeight1"
app:layout_constraintRight_toLeftOf="#+id/guidelineNavHeight2">
</TextView>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guidelineNavHeight2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.70" />
<TextView
android:id="#+id/timeHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Time"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/guidelineNavHeight2"
app:layout_constraintRight_toLeftOf="#+id/zoneHeader">
</TextView>
<TextView
android:id="#+id/zoneHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(CST/CDT)"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/timeHeader"
app:layout_constraintRight_toRightOf="parent">
</TextView>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/headerCL">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/eventsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Below is my item layout, event_item.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp">
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="#+id/guidelineNavHeight1">
</TextView>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guidelineNavHeight1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.25" />
<TextView
android:id="#+id/event"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/guidelineNavHeight1"
app:layout_constraintRight_toLeftOf="#+id/timeHeader">
</TextView>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guidelineNavHeight2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.70" />
<TextView
android:id="#+id/time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/guidelineNavHeight2"
app:layout_constraintRight_toRightOf="parent">
</TextView>
</androidx.constraintlayout.widget.ConstraintLayout>
I think your events fragrment constraint layout height should be match_parent
Related
For some reason the TextViews in my ConstraintLayout won't move at all and are stuck in the middle. How can I move them to the Left/Start position? I tried the following but neither of these worked. Any ideas on what else to use?
android:gravity="start"
app:flow_horizontalBias="0.0"
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayoutB"
android:foreground="?android:attr/selectableItemBackground">
<!--Constraint 1-->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/constraintLayoutBTitle"
android:layout_marginBottom="10dp">
<ImageButton
android:id="#+id/ibB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="?attr/selectableItemBackgroundBorderless"/>
<TextView
android:id="#+id/tvB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="#+id/ibB1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constrainedWidth="true"
style="#android:style/TextAppearance.Medium"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<!--Constraint 2-->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/constraintLayoutBContent">
<ImageView
android:id="#+id/ivB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/ic_launcher_round" />
<TextView
android:id="#+id/tvB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
app:flow_horizontalBias="0.0"
app:layout_constraintStart_toEndOf="#+id/ivB2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/ivB2"
app:layout_constrainedWidth="true"
style="#android:style/TextAppearance.Medium"/>
<TextView
android:id="#+id/tvB3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toTopOf="#+id/tvB4"
app:layout_constraintStart_toEndOf="#+id/ivB2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/ivB2"
app:layout_constrainedWidth="true"
style="#android:style/TextAppearance.Medium"/>
<ImageView
android:id="#+id/ivB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="#+id/ivB2"
app:layout_constraintStart_toStartOf="#+id/ivB2"
app:layout_constraintTop_toBottomOf="#+id/ivB2"
app:layout_constraintTop_toTopOf="#+id/tvB4"
app:srcCompat="#mipmap/ic_launcher_round" />
<TextView
android:id="#+id/tvB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constraintStart_toEndOf="#+id/ivB4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvB3"
app:layout_constraintTop_toTopOf="#+id/ivB4"
app:layout_constrainedWidth="true"
style="#android:style/TextAppearance.Medium"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Here it is, I just set bias to 0.0.
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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"
app:cardUseCompatPadding="true">
<LinearLayout
android:id="#+id/linearLayoutB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="vertical">
<!--Constraint 1-->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayoutBTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp">
<ImageButton
android:id="#+id/ibB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tvB1"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/ibB1"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<!--Constraint 2-->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayoutBContent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/ivB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/ic_launcher_round" />
<TextView
android:id="#+id/tvB2"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/ivB2"
app:layout_constraintTop_toTopOf="#+id/ivB2"
tools:text="2a" />
<TextView
android:id="#+id/tvB3"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="#+id/tvB4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/ivB2"
app:layout_constraintTop_toBottomOf="#+id/ivB2"
tools:text="2b" />
<ImageView
android:id="#+id/ivB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="#+id/ivB2"
app:layout_constraintStart_toStartOf="#+id/ivB2"
app:layout_constraintTop_toBottomOf="#+id/ivB2"
app:layout_constraintTop_toTopOf="#+id/tvB4"
app:srcCompat="#mipmap/ic_launcher_round" />
<TextView
android:id="#+id/tvB4"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/ivB4"
app:layout_constraintTop_toBottomOf="#+id/tvB3"
tools:text="2c" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Result:
But I think in Your layout You have added too many constraints. You don't have to set the constraint to the end of the card view for every textView. It will automatically go to start if You just add one.
If you want to get something like that, copy the code below.
android:layout_width="0dp"
The key to put the textView to the left is expand the textview to match the constraint.
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayoutB"
android:foreground="?android:attr/selectableItemBackground">
<!--Constraint 1-->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/constraintLayoutBTitle"
android:layout_marginBottom="10dp">
<ImageButton
android:id="#+id/ibB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="?attr/selectableItemBackgroundBorderless"/>
<TextView
android:id="#+id/tvB1"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tvB1"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/ibB1"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<!--Constraint 2-->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayoutBContent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/ivB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/ic_launcher_round" />
<TextView
android:id="#+id/tvB2"
style="#android:style/TextAppearance.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb2"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="#+id/ivB2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/ivB2"
app:layout_constraintTop_toTopOf="#+id/ivB2" />
<TextView
android:id="#+id/tvB3"
style="#android:style/TextAppearance.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb3"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="#+id/tvB4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/ivB2"
app:layout_constraintTop_toTopOf="#+id/ivB4" />
<ImageView
android:id="#+id/ivB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="#+id/ivB2"
app:layout_constraintTop_toBottomOf="#+id/ivB2"
app:srcCompat="#mipmap/ic_launcher_round" />
<TextView
android:id="#+id/tvB4"
style="#android:style/TextAppearance.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb4"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/ivB4"
app:layout_constraintTop_toBottomOf="#+id/tvB3" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
In my Android studio project I have a fragment with constraint layout inside. Here is XML.
<android.support.constraint.ConstraintLayout
android:id="#+id/pinLayout"
android:layout_width="match_parent"
android:layout_height="250dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/topLayout">
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/constraintLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<TextView
android:id="#+id/numberTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="top"
android:text="00000000"
android:textColor="#color/appTintColor"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/confirmButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner_shape_tint"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Confirm Pin"
android:textColor="#color/appMainColor"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/constraintLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintStart_toStartOf="parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/pinView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
As you can see the confirm button is centered with constraints in his parent.
But when I am running application in my Xperia z5 compact, a layout inspector shows that button is not centered.
Why does it happen and how to fix that?
Note if I am removing numberTextView with it's parent constarintLayout, the problem disappears.
Note In my code I am programmatically setting a text to numberTextView. In case when I am commenting that code i.e not setting text programmatically, button draws correctly.
Here is code part, where I am setting text to NumberTextView
private void performInitialLayout() {
fragmentViewHeight = fragmentView.getHeight();
ViewRelatedUtils.setHeightPercentage(topView, scrollView, 0.3);
ViewRelatedUtils.setHeightPercentage(pinLayout, scrollView, 0.4);
// here I am setting a text.
numberTextView.setText(number);
if (isProcessingPinConfirmation) showProcessing(); else hideProcessing();
wrapperView.requestFocus();
performedInitialLayout = true;
}
Please read my comment on the question, although I have made some changes to your layout, check this out
Change the colors as per your requirement.
<?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/linearLayout17"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/hint_color">
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/constraintLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<TextView
android:id="#+id/numberTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="top"
android:text="00000000"
android:textColor="#color/txt_color"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/confirmButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_rounded_button"
android:padding="14dp"
android:text="Confirm Pin"
android:textColor="#color/colorPrimary"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/constraintLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintStart_toStartOf="parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/pinView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/txt_color"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/txt_color"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/txt_color"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/txt_color"
android:textSize="36sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
In my Android studio project I have a fragment with constraint layout inside. Here is XML.
<android.support.constraint.ConstraintLayout
android:id="#+id/pinLayout"
android:layout_width="match_parent"
android:layout_height="250dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/topLayout">
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/constraintLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<TextView
android:id="#+id/numberTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="top"
android:text="00000000"
android:textColor="#color/appTintColor"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/confirmButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner_shape_tint"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Confirm Pin"
android:textColor="#color/appMainColor"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/constraintLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintStart_toStartOf="parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/pinView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
As you can see the confirm button is centered with constraints in his parent.
But when I am running application in my Xperia z5 compact, a layout inspector shows that button is not centered.
Why does it happen and how to fix that?
Note if I am removing numberTextView with it's parent constarintLayout, the problem disappears.
Note In my code I am programmatically setting a text to numberTextView. In case when I am commenting that code i.e not setting text programmatically, button draws correctly.
app:layout_constraintHorizontal_bias="0.5"
layout_constraintHorizontal_bias this will make a small variation from center. try code given below,
<Button
android:id="#+id/confirmButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner_shape_tint"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Confirm Pin"
android:textColor="#color/appMainColor"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Remove the below line from your button layout in xml.
app:layout_constraintHorizontal_bias="0.5"
Horizontal Bias:
This allows us to position a view along the horizontal axis using a bias value, this will be relative to it’s constrained position.
For more information about Constraint Layout refer
this article
android:id="#+id/pinLayout" has hight of 250dp that's why button doesn't position at vertically center. try the code given below.
<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.support.constraint.ConstraintLayout
android:id="#+id/pinLayout"
android:layout_width="match_parent"
android:layout_height="250dp">
<android.support.constraint.ConstraintLayout
android:id="#+id/cl_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<TextView
android:id="#+id/numberTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="top"
android:text="00000000"
android:textColor="#color/appTintColor"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/cl_root"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintStart_toStartOf="parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/pinView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
<TextView
android:id="#+id/pinView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:text="-"
android:textColor="#color/appTintColor"
android:textSize="36sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/confirmButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner_shape_tint"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Confirm Pin"
android:textColor="#color/appMainColor"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
try to use RelativeLayout instead of ConstraintLayout by changing all ConstraintLayout to RelativeLayout in your xml
<android.support.constraint.ConstraintLayout >
...
Your content
...
</android.support.constraint.ConstraintLayout>
to
<RelativeLayout >
...
Your content
...
</RelativeLayout>
then you might give set your button to be center in parent
android:layout_centerInParent="true"
for your TextView pinView1, pinView2, pinView3 and pinView4 you have simply put it inside a LinearLayout.
I want to make layout with two text fields, which will have 40/60 ratio (like on image below) throw contraint. I can see result on preview on layout in Android Studio (see the image below), but when I start my app, the string becomes invisible, like contraint doesn't work. But if I will but istead of 0dp wrap_conent, both textViews becomes visible, but text with wrap_content has width more, then 0.4 or 0.6. How to fix this? Or maybe there is another way to impelement this?
<?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="wrap_content"
android:paddingBottom="8dp">
<TextView
android:id="#+id/name"
app:layout_constraintWidth_percent="0.4"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="LeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeft" />
<TextView
android:id="#+id/value"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.6"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/black"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline"
tools:text="RightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRight" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintGuide_percent="0.4" />
</android.support.constraint.ConstraintLayout>
Remove the constraints from your guideline, remove the layout_constraintWidth_percent from your textviews and instead constrain them on your guideline, while dding the appropriate start and end constraints as follows:
<?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="wrap_content"
android:paddingBottom="8dp">
<TextView
android:id="#+id/name"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/guideline"
tools:text="LeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeft" />
<TextView
android:id="#+id/value"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/black"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
tools:text="RightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRight" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.4" />
</android.support.constraint.ConstraintLayout>
<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="wrap_content"
android:paddingBottom="8dp">
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.5"
tools:text="LeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeft" />
<TextView
android:id="#+id/value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/colorPrimary"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/name"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.5"
tools:text="RightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRight" />
</android.support.constraint.ConstraintLayout>
I have added 2 more constraints, check this answer and see if this will work:
<?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="wrap_content"
android:paddingBottom="8dp">
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.4"
tools:text="LeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeftLeft" />
<TextView
android:id="#+id/value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.6"
tools:text="RightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRightRight" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintGuide_percent="0.4" />
</android.support.constraint.ConstraintLayout>
I have a XML layout as follows:
<?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:card_view="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/accounts_details_page_background_color">
<android.support.v7.widget.CardView
android:id="#+id/overview_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
card_view:cardElevation="2dp"
card_view:ignore="PrivateResource">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp">
<TextView
android:id="#+id/fragment_compliance_details_overview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="#string/compliance_details_fragment_overview"
android:textColor="#color/compliance_overview_title_color"
android:textSize="#dimen/text_size_small"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/policy_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:textColor="#color/black"
android:textSize="#dimen/text_size_large"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/fragment_compliance_details_overview" />
<TextView
android:id="#+id/last_check_time_only"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/text_size_small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/policy_name" />
<View
android:id="#+id/horizontal_line_compliance"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="16dp"
android:background="?android:attr/listDivider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/last_check_time_only" />
<TextView
android:id="#+id/compliance_policy_status_explanation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="#dimen/text_size_small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/horizontal_line_compliance" />
<TextView
android:id="#+id/last_check_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="#string/last_compliance_check_time"
android:textSize="#dimen/text_size_small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/compliance_policy_status_explanation" />
<TextView
android:id="#+id/compliance_user_action_advice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="#string/compliance_user_advice"
android:textSize="#dimen/text_size_small"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/last_check_time" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/details_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/overview_cardview"
app:layout_constraintVertical_bias="0.0"
card_view:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:orientation="vertical">
<TextView
android:id="#+id/policy_details_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="#string/policy_details_title"
android:textColor="#color/compliance_overview_title_color"
android:textSize="14sp"
android:textStyle="bold"
android:visibility="gone" />
<ListView
android:id="#+id/compliance_rules_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
When the ListView has more than 3-4 rows the page does not scroll. The ListView does not scroll either.
I tried wrapping the whole thing in a NestedScrollView but that just gets the ListView scrolling and not even entirely.
I want the entire page to scroll and end scrolling when the ListView ends. Any ideas would help.
You don't need constraint layout for what you are doing.
Read about view weights.
Try this. (replace androix.* for your components)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="#+id/overview_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#color/white"
app:cardUseCompatPadding="true"
app:contentPadding="4dp"
card_view:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/fragment_compliance_details_overview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/policy_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:textColor="#color/black"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/fragment_compliance_details_overview" />
<TextView
android:id="#+id/last_check_time_only"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/policy_name" />
<View
android:id="#+id/horizontal_line_compliance"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="16dp"
android:background="?android:attr/listDivider" />
<TextView
android:id="#+id/compliance_policy_status_explanation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="test"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/horizontal_line_compliance" />
<TextView
android:id="#+id/last_check_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="test"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/compliance_policy_status_explanation" />
<TextView
android:id="#+id/compliance_user_action_advice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="#string/has_accepted_your_invitation_to_fynd"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/last_check_time" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/details_cardview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white"
app:cardUseCompatPadding="true"
app:contentPadding="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/overview_cardview"
app:layout_constraintVertical_bias="0.0"
card_view:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/policy_details_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="test"
android:textSize="14sp"
android:textStyle="bold" />
<ListView
android:id="#+id/compliance_rules_listview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>