1

here i am asking for your help.

I'm trying to implement a nestedscrollview inside a coordinatorlayout with some other stuff but the nestedscroll view keeps transparent no matter what i do.

I have already thought a lot but couldn't find any solution.

I want it to have a "solid" white background not this (+/- 30% white) background, here as some printscreens:

Before

Then when i start it sliding:

After

As we can see it the background text (that is inside the coordinator but out the nested) still readable and i can even start actions like press the drawer button that should be hidden.

Here is my main layout code which hold the NestedScrollView:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:scrollbars="none"
        app:behavior_hideable="true"
        app:behavior_peekHeight="64dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

        <include layout="@layout/fragment_fast_access" />

    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

And this is the Fragment i want to show inside it:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FastAccessFragment">

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="288dp" />

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="64dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="64dp">

            <ImageView
                android:id="@+id/fastAccess_inCard_coverAlbum"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_gravity="center"
                android:layout_marginStart="16dp"
                android:contentDescription="@string/album_cover"
                android:scaleType="centerCrop"
                android:src="@drawable/gradient_bg_main"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/fastAccess_inCard_songName"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginHorizontal="16dp"
                android:layout_marginBottom="2dp"
                android:ellipsize="end"
                android:gravity="bottom"
                android:maxLines="1"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="@android:color/black"
                app:layout_constraintBottom_toTopOf="@id/fastAccess_inCard_artistName"
                app:layout_constraintEnd_toStartOf="@id/fastAccess_inCard_buttonPlay"
                app:layout_constraintStart_toEndOf="@id/fastAccess_inCard_coverAlbum"
                app:layout_constraintTop_toTopOf="parent"
                tools:text="Song name" />

            <TextView
                android:id="@+id/fastAccess_inCard_artistName"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginHorizontal="16dp"
                android:ellipsize="end"
                android:maxLines="1"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@id/fastAccess_inCard_buttonPlay"
                app:layout_constraintStart_toEndOf="@id/fastAccess_inCard_coverAlbum"
                app:layout_constraintTop_toBottomOf="@id/fastAccess_inCard_songName"
                tools:text="Artist" />

            <ImageButton
                android:id="@+id/fastAccess_inCard_buttonPlay"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_marginEnd="16dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:contentDescription="@string/button_play"
                android:focusable="true"
                android:src="@drawable/ic_play"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@id/fastAccess_inCard_buttonPlaylist"
                app:layout_constraintTop_toTopOf="parent" />

            <ImageButton
                android:id="@+id/fastAccess_inCard_buttonPlaylist"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="16dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:contentDescription="@string/show_playlist"
                android:focusable="true"
                android:scaleType="centerCrop"
                android:src="@drawable/ic_playlist"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

Thanks in advance ;)

Groot
  • 37
  • 4
  • You are basically putting a lot of views in a single layout file. What kind of screen do you want? And since, `NestedScrollView` has `layout_width` and `layout_height` of `match_parent`, it's gonna fill up the entire screen. So, you need to find an appropriate view to put it inside a `NestedScrollView` since, it only accept a single child view. – cgb_pandey May 28 '20 at 03:13
  • Hi thanks for answer, but they need to be ```match_parent``` because i want them to fill the whole screen, the problem is that when i scroll my fragment to top, it does not override my appbar, actualy now i can override it in api > 23, and after 23 the appbar still visible and even clickable – Groot May 28 '20 at 04:51
  • Do you want a `ScrollingActivity` like this with `CollapsingAppBar`? There is a template in the Android Studio which will create one for you. https://i.stack.imgur.com/AWenW.png – cgb_pandey May 28 '20 at 05:27
  • Hi @cgb_pandey , no i want is something like google apps does (like music for example), when you have a "hidden piece of fragment" in the bottom part of your activity and when you slide it from the bottom to the top it fill the whole screen ( hidding things inside the activity and showing all the fragment), but in my case i cant reach this, mine stays "like a 30% visible" like in screenshots. I don't know if i was very clear because i don't know how sould i call this "feature", but thanks for the answer :) – Groot May 28 '20 at 18:45
  • I think what you are talking about is called MaterialContainerTransform. It can be used to morph from one view to another another within the same screen or to different activity or to different fragment. Check out this blog post: https://proandroiddev.com/implementing-the-motion-system-with-material-components-for-android-75bfeef8de9e – cgb_pandey May 28 '20 at 23:57
  • Hi @cgb_pandey, i found that i need to set ```android:fillViewport="true"```to fill the whole screen and.... Problem solved lol, a lot of time to find this line, but worked fine, thanks for the help – Groot May 29 '20 at 20:08

0 Answers0