Android Textview not aligning to top of page - java

I am having trouble aligning my UI components to top of the constraint layout even though I have constraint them to the start of the page. There is a tiny gap between the ToolBar and where the UI components start. app:layout_constraintTop_toTopOf="parent" -> this line of code always works but I believe the problem could be that I am using a tabbed activity that it might not be compatible.Problem in UI
Any help or guidance would be greatly appreciated.
This is my XML class ->
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:id="#+id/breakfastTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
android:layout_weight="10"
android:text="Breakfast"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/breakfastRecyclerView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/breakfastTV" />
<TextView
android:id="#+id/lunchTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
android:layout_weight="10"
android:text="Lunch"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/breakfastRecyclerView" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/lunchRecyclerView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/lunchTV" />
<TextView
android:id="#+id/dinnerTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
android:layout_weight="10"
android:text="Dinner"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/lunchRecyclerView" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/dinnerRecyclerView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/dinnerTV" />
<TextView
android:id="#+id/otherTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
android:layout_weight="10"
android:text="Other"
android:textAppearance="#style/TextAppearance.AppCompat.Body2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/dinnerRecyclerView" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/otherRecyclerView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/otherTV" />
</androidx.constraintlayout.widget.ConstraintLayout>
CLASS WITH Toolbar ->
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/a"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Management"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
<FrameLayout
android:id="#+id/fragLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/topNavigation"
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="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/topNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/mgmt_bottom_nav_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>

Related

FrameLayout with Recyclerview

I want to put the bottom navigation menu with my recyclerview at the bottom of the view. It is currently at the top and I need help sending it to the bottom.
This is how it look now:
This 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"
tools:context=".MainActivity">
<TextView
android:id="#+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Oficinas Credenciadas"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView" />
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintTop_toBottomOf="#+id/titleTextView"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/botton_nav_menu"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
Add
app:layout_constraintBottom_toBottomOf="parent"
To bottom navigation item so code will be like that
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/botton_nav_menu"
tools:ignore="MissingConstraints" />
I have made some changes and this is how it the items are positioned now.
This is how the code looks now. If this helps you, an upvote would be appreciated. Thanks
<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">
<TextView
android:id="#+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Oficinas Credenciadas"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toTopOf="#+id/bottom_menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView" />
<!-- NOT SURE WHY YOU HAVE THE FRAMELAYOUT AND RECYCLERVIEW OCCUPYING THE SAME SPACE BUT IF YOU INTEND TO HIDE AND SHOW THEM AT DIFFERENT TIMES, I HAVE IMPROVED THEIR CONSTRAINTS -->
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintBottom_toTopOf="#+id/bottom_menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/sample_menu"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>

Why is my RecyclerView is invisible inside ScrollView?

I have a scrollView in my xml. There's ConstraintLayout inside of it. In the ConstraintLayout is my RecyclerView. It's invisible. When I change ScrollView to ConstraintLayout everything gets back to normal. Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
tools:context=".ui.fragments.ChannelAudioFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/allChannelAudiosProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
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" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/noAudiosTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:gravity="center|left"
android:text="No audios"
android:layout_marginTop="5dp"
android:textSize="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/channelAudiosRefreshSwipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingConstraints">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvAllChannelAudios"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I don't get any errors in console. Why is this happening?
UPDATE
Additional info: I'm using it in ViewPager. Here it is
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.fragments.ChannelFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/channelBlock"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_margin="30dp"
android:background="#drawable/main_background"
android:padding="20dp"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ivChannelImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/ic_person_flat"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Qewbite"
android:textColor="#color/whiteColor"
android:layout_marginTop="8dp"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/ivChannelImage" />
<LinearLayout
android:id="#+id/subscriptionBlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/channelName"
android:gravity="center_vertical">
<Button
android:id="#+id/subscribeButton"
android:layout_width="wrap_content"
android:textAllCaps="false"
android:layout_height="40dp"
android:textSize="12dp"
android:gravity="center"
android:background="#drawable/subscribed_background"
android:padding="0dp"
app:backgroundTint="#color/colorDark"
android:textColor="#color/whiteColor"
android:layout_marginLeft="5dp"
android:text="Unfollow" />
<ImageButton
android:id="#+id/notificationButton"
android:layout_width="40dp"
android:textAllCaps="false"
android:layout_height="40dp"
android:textSize="12dp"
android:tint="#color/whiteColor"
android:src="#drawable/ic_notification"
app:backgroundTint="#color/colorDark"
android:background="#drawable/subscribe_notification_background"
android:padding="0dp"
android:textColor="#color/whiteColor" />
</LinearLayout>
<View
android:id="#+id/headerHr"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorNavbarGray"
app:layout_constraintTop_toBottomOf="#id/subscriptionBlock"
android:layout_marginTop="10dp"
/>
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelSubscribers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10M"
android:textColor="#color/whiteColor"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#id/channelSubscribersTitle"
app:layout_constraintEnd_toEndOf="#id/channelSubscribersTitle"
app:layout_constraintTop_toBottomOf="#id/headerHr" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelSubscribersTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Followers"
android:textColor="#color/colorLightGray"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/channelSubscribers" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelListened"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="120M"
android:textColor="#color/whiteColor"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#id/channelListenedTitle"
app:layout_constraintEnd_toEndOf="#id/channelListenedTitle"
app:layout_constraintTop_toBottomOf="#id/headerHr" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelListenedTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Auditions"
android:textColor="#color/colorLightGray"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/channelListened" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2021"
android:textColor="#color/whiteColor"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/headerHr" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelYearTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Year"
android:textColor="#color/colorLightGray"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="#id/channelYear"
app:layout_constraintEnd_toEndOf="#id/channelYear"
app:layout_constraintTop_toBottomOf="#id/channelSubscribers" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="#color/colorPrimary"
app:layout_constraintTop_toBottomOf="#id/channelBlock"
app:layout_constraintStart_toStartOf="#id/channelBlock"
app:tabRippleColor="#color/colorGray"
android:layout_marginTop="8dp" />
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/channelViewPager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="#id/tab"
app:layout_constraintStart_toStartOf="#id/tab" />
</androidx.constraintlayout.widget.ConstraintLayout>
Most probably that is because you put more than 1 view inside ScrollView , ScrollView expects 1 view from you. If you want to put more than one consider using a viewGroup view and put your views inside it. For Instance , you can use a vertical LinearLayout to wrap the Views you used. Also , consider using NestedScrollView instead.
Try this one
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
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">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
>
<ProgressBar
android:id="#+id/allChannelAudiosProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
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" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/noAudiosTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:gravity="center|left"
android:text="No audios"
android:layout_marginTop="5dp"
android:textSize="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvAllChannelAudios"
tools:listitem="#layout/event_near_items"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:itemCount="10"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
swipe_refresh.setOnRefreshListener {
swipe_refresh.isRefreshing = false
// refresh the list here
}
Why not try a nested scroll view.

Toolbar, BottomNavigationView and FrameLayout in one XML layout

I need help in my XML layout, since I need to put Toolbar, FrameLayout, BottomNavigationView in one activity, Below is my code, the problem that the toolbar not appeared only the FrameLayout and BottomNavigationView
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<include
android:id="#+id/app_bar"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
layout="#layout/app_bar_layout" />
<FrameLayout
android:id="#+id/activity_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/bottom_navigation"
app:layout_constraintTop_toBottomOf="#+id/app_bar"
/>
<View
android:id="#+id/horizontalDivider"
android:layout_width="match_parent"
android:layout_height="0.3dp"
android:layout_above="#+id/bottom_navigation"
android:layout_gravity="center_vertical"
android:background="#android:color/black" />
<include
android:id="#+id/bottom_navigation"
layout="#layout/bottom_navigation"
android:layout_alignParentBottom="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
</android.support.constraint.ConstraintLayout>
Try this
<android.support.constraint.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">
<include
android:id="#+id/app_bar"
layout="#layout/aa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="#+id/activity_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#color/colorAccent"
app:layout_constraintBottom_toTopOf="#+id/horizontalDivider"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/app_bar" />
<View
android:id="#+id/horizontalDivider"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_gravity="center_vertical"
android:background="#android:color/black"
app:layout_constraintBottom_toTopOf="#+id/bottom_navigation"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/activity_content" />
<include
android:id="#+id/bottom_navigation"
layout="#layout/aa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/horizontalDivider" />
</android.support.constraint.ConstraintLayout>
OUTPUT

how to set content of textview to toolbar when scrolling in Collapsingtoolbarlayout?

I have an activity with CollapsingToolbarLayout and with a lot of widgets in NestedScrollingview that I use for details of products ... I want when scrolling the activity to up the title that is below the slider goes to the toolbar and show on the toolbar... Must I add more attributes in .xml or write code in .java?
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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"
android:fitsSystemWindows="true"
android:background="#color/bg_main"
tools:context=".DetailsActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="#android:color/transparent"
android:fitsSystemWindows="true">
<com.daimajia.slider.library.SliderLayout
android:id="#+id/sliderdetails"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin">
<ImageView
android:id="#+id/img_cardtool"
android:layout_width="25dp"
android:layout_height="35dp"
android:src="#drawable/ic_shop"
android:layout_marginLeft="20dp"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="0dp"
android:layout_marginBottom="0dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg_caption_details"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dp"
android:layout_gravity="left">
<ImageView
android:id="#+id/img_sharedetail"
android:layout_width="25dp"
android:layout_height="35dp"
android:src="#drawable/ic_shareb"
android:layout_marginLeft="5dp"
/>
<ImageView
android:id="#+id/img_notificationdetail"
android:layout_width="25dp"
android:layout_height="35dp"
android:src="#drawable/ic_notification"
android:layout_marginLeft="20dp"
/>
<ImageView
android:id="#+id/img_bookmarddetail"
android:layout_width="25dp"
android:layout_height="35dp"
android:src="#drawable/ic_fav"
android:layout_marginLeft="20dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="#+id/txtcaptiondetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:hint=" عنوان اصلی محصول"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#color/black"/>
<TextView
android:id="#+id/txtcaptiondescdetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:hint=" عنوان دوم محصول"
android:textSize="14sp"
android:layout_marginTop="5dp"
android:textColor="#color/twotitle"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:foreground="?attr/selectableItemBackground"
android:background="#drawable/cardviewrounded"
android:clickable="true"
android:padding="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/cardView2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.517">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/txtdesc"
android:src="#drawable/ic_contet" />
<TextView
android:id="#+id/txtdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="مشخصات"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:foreground="?attr/selectableItemBackground"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/cardView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/txtrespo"
android:src="#drawable/ic_response" />
<TextView
android:id="#+id/txtrespo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:text="نظرات کاربران"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

CollapsingToolbar - overlap with correct anchoring

I'm trying to create a CollapsingToolbarLayout in which the there is a movie poster overlapping the backdrop. To achieve this I'm enabling behavior_overlapTop="67dp" but this results in a strange scrolling behavior.
When scrolling, my views are pushed away from their overlapping position. How do I make them stay in place?
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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"
android:fitsSystemWindows="true"
tools:context=".MediaItemBaseActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="1dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="#color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar"
app:scrimAnimationDuration="250"
app:scrimVisibleHeightTrigger="100dp">
<ImageView
android:id="#+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="20dp"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_overlapTop="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MediaItemBaseActivity"
tools:showIn="#layout/activity_media_item_base">
<android.support.constraint.ConstraintLayout
android:id="#+id/ll_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<ImageView
android:id="#+id/poster"
android:layout_width="134dp"
android:layout_height="201dp"
android:layout_gravity="top|start"
android:layout_marginTop="-10dp"
android:elevation="10dp"
app:layout_anchor="#id/ll_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/surtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:textAllCaps="false"
android:textSize="14sp"
app:layout_constraintBottom_toTopOf="#+id/title"
app:layout_constraintStart_toStartOf="#+id/title" />
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="96dp"
android:ellipsize="end"
android:maxEms="9"
android:maxLines="3"
android:singleLine="false"
android:textAllCaps="false"
android:textColor="#android:color/black"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/poster"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textAllCaps="false"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="#+id/surtitle"
app:layout_constraintTop_toBottomOf="#+id/title" />
<TextView
android:id="#+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/text_margin"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/poster" />
<TextView
android:id="#+id/credit_title_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/body" />
<TextView
android:id="#+id/credit_name_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintStart_toEndOf="#id/credit_title_1"
app:layout_constraintTop_toTopOf="#id/credit_title_1" />
<TextView
android:id="#+id/credit_title_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/credit_name_1" />
<TextView
android:id="#+id/credit_name_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="#+id/credit_name_1"
app:layout_constraintTop_toTopOf="#id/credit_title_2" />
<TextView
android:id="#+id/credit_title_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/credit_name_2" />
<TextView
android:id="#+id/credit_name_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="#+id/credit_name_2"
app:layout_constraintTop_toTopOf="#id/credit_title_3" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="#drawable/ic_add_black_24dp" />
</android.support.design.widget.CoordinatorLayout>
What is happening here is that both the CollapsingToolbar and the NestedScrollView is getting scrolled which is obvious. To get the effect you probably want(similar to FAB but with the view visible even when collapsed), you need to extend the CoordinatorLayout.Behaiour class to make your own behaviour. Setting behavior_overlapTop="67dp" wont do anything except what it seems to be doing right now.

Categories