Reputation: 926
So I've got this UI where I have an image at the very top of my screen, with two texts below. I want my text to overlap the bottom of the image and then below all of this, I have a recyclerview . With my current UI, it seems like the Text overlapping the image is just fine, but I can't get it to scroll. If I put match_parent on my recyclerview, I can scroll everything but the Text suddenly isn't fine. I want the entire screen to scroll, not just the recyclerview, which is why I have it all inside a NestedScrollView. Hopefully someone can spot my mistake, I've been at it for too long and it annoys me. :)
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/some_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
style="@style/TextView.H1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Overlapping Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/image"
app:layout_constraintVertical_bias="0.25" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/sub_title"
style="@style/TextView.Dark.H5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Subtitle below Overlapping"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="56dp"
android:nestedScrollingEnabled="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sub_title" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Due to this being for a client, I can't show an image of the design. I've made a quick mock in paint trying to explain what I want.
Upvotes: 0
Views: 60
Reputation: 113
I have updated your code and used LinearLayout instead of ConstraintLayout. Check the below code
<androidx.core.widget.NestedScrollView 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"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/ic_round_icon_48dp" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Overlapping Text"
app:layout_constraintVertical_bias="0.25" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/sub_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtitle below Overlapping" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="56dp"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Upvotes: 2
Reputation: 889
Nesting scrolls was never a good idea. You should avoid this at all costs, one scroll messes with another. Reconsider changing your layout structure.
What do you want to do? Please, when posing questions that describe layouts, just attach images. I didn't undertand exactly what you want.
Upvotes: 0