Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

android - ConstraintLayout from bottom to top

I have layout like this:

<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="match_parent">

<androidx.fragment.app.FragmentContainerView
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="@color/colorPrimary"
    android:minHeight="300dp"
    app:layout_constraintBottom_toTopOf="@+id/recyclerView"
    app:layout_constraintHeight_min="300dp"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

FragmentContainerView and RecyclerView have dynamic sizes, and FragmentContainerView should not be less than 300dp and fit all available spase. RecyclerView should be on the bottom and can contains from 1 to 20 items. Current solution works ok only for case RecyclerView contains few items, but for other case it overlaps FragmentContainerView. Is it possible to align RecyclerView to bottom but restrict max size to have free space = 300dp at the top?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you need to do:

  • Add app:layout_constraintTop_toBottomOf="@id/container" to the RecyclerView
  • Remove app:layout_constraintBottom_toTopOf="@+id/recyclerView" From the FragmentContainerView

This will make the FragmentContainerView height not restricted to the height of the RecyclerView .. and Make the RecyclerView height limited between the bottom of the FragmentContainerView & the bottom of the parent.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...