FloatingActionButton between layouts with CollapsingToolbarLayout - android

I would like to add a floating action button between two layouts with different elevation to get something like this:
This is my layout, but probably it's overcomplicated:
<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:theme="#style/AppTheme.NoActionBar">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="#color/color_primary"
app:scrimAnimationDuration="300"
app:titleEnabled="false"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">
<ImageView
android:id="#+id/trailer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:ignore="ContentDescription" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat"
app:layout_collapseMode="pin" />
</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:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#color/color_primary"
android:elevation="16.0dp">
<com.est.streamcorn.views.AspectRatioImageView
android:id="#+id/image"
android:layout_width="150dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:scaleType="centerInside"
android:theme="#style/MoviePosterImage"
tools:ignore="ContentDescription"
app:elevation="6dp"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:elevation="6dp"
app:srcCompat="#drawable/player_action_play"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#id/image"/>
<TextView
android:id="#+id/link1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/title"
app:layout_constraintStart_toEndOf="#id/image"/>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
All the examples I found anchor the floating button to the coordinator layout, but I would like to have it fixed like the other elements inside the NestedScrollView. Mybe there is a better way to accomplish the different color and elevation without needing two different layouts?

At the end I was able to achieve this:
This is the layout:
<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/colorPrimaryReverse"
android:theme="#style/AppTheme.NoActionBar">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="220dp"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar">
<com.est.streamcorn.views.CustomCollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:scrimAnimationDuration="250"
app:titleEnabled="false"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">
<ImageView
android:id="#+id/trailer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scaleType="centerCrop"
tools:ignore="ContentDescription"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat"
app:layout_collapseMode="pin">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:layout_marginEnd="5dp"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title" />
</android.support.v7.widget.Toolbar>
</com.est.streamcorn.views.CustomCollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_overlapTop="40dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:layout_margin="20dp"
app:elevation="6dp"
app:srcCompat="#drawable/player_action_play"
app:backgroundTint="#color/colorAccent"
app:layout_anchor="#id/header"
app:layout_anchorGravity="bottom|right|end"/>
<android.support.v7.widget.CardView
android:id="#+id/image_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
app:cardElevation="6dp"
app:cardCornerRadius="6dp"
app:layout_anchor="#id/header"
app:layout_anchorGravity="top|left|start">
<com.est.streamcorn.views.AspectRatioImageView
android:id="#+id/image"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
tools:ignore="ContentDescription"
app:aspectRatio="#dimen/movie_poster_aspect_ratio" />
</android.support.v7.widget.CardView>
<FrameLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="170dp"
android:background="#android:color/transparent"
android:elevation="4.0dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:background="#color/colorPrimaryReverse"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_marginBottom="0dp"
android:paddingEnd="0dp"
android:paddingStart="135dp">
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
android:textAppearance="#style/MovieDetail.Title"
app:layout_constraintBottom_toTopOf="#id/text1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#id/download"
app:layout_constraintHorizontal_weight="0"
tools:text="The Martian - A Test Movie As Placeholder" />
<TextView
android:id="#+id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="#style/MovieDetail.Text1"
app:layout_constraintBottom_toTopOf="#id/text2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#id/download"
android:layout_marginBottom="5dp"
tools:text="2015" />
<TextView
android:id="#+id/text2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="#style/MovieDetail.Text2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#id/download"
android:layout_marginBottom="15dp"
tools:text="141 minutes" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:background="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="#id/title"
app:layout_constraintTop_toTopOf="#id/title"
app:layout_constraintEnd_toEndOf="parent"
app:backgroundTint="#android:color/transparent"
app:borderWidth="0dp"
app:elevation="0dp"
app:srcCompat="#drawable/ic_download"
tools:ignore="ContentDescription" />
</android.support.constraint.ConstraintLayout>
</FrameLayout>
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="150dp"
android:background="#color/backgroundColorReverse"
android:orientation="vertical"
android:paddingEnd="15dp"
android:paddingStart="15dp"
android:paddingTop="60dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textSize="16sp"
android:textAllCaps="true"
android:textColor="#color/textColorPrimaryReverse"
android:text="#string/description" />
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
The custom view:
public class CustomCollapsingToolbarLayout extends CollapsingToolbarLayout {
private Boolean previousShowing = true;
public static interface Listener {
public void onContentScrimAnimationStarted(boolean showing);
}
private Listener mListener;
public CustomCollapsingToolbarLayout(Context context) {
super(context);
}
public CustomCollapsingToolbarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomCollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public void setScrimsShown(boolean shown, boolean animate) {
super.setScrimsShown(shown, animate);
if (animate && mListener != null && shown != previousShowing) {
mListener.onContentScrimAnimationStarted(shown);
previousShowing = shown;
}
}
public void setListener(Listener listener) {
mListener = listener;
}
}
And in the activity OnCreate:
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
TypedValue tv = new TypedValue();
getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
final int actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId);
collapsingToolbarLayout.setScrimVisibleHeightTrigger(actionBarHeight + 100);
collapsingToolbarLayout.setListener(showing -> {
if(showing){
toolbarTitle.setVisibility(View.VISIBLE);
toolbarTitle.animate().alpha(1).setDuration(250);
}
else{
toolbarTitle.setVisibility(View.INVISIBLE);
toolbarTitle.animate().alpha(0).setDuration(250);
}
});
The custom view is needed only if you want to make the title disappear when expanding the CollapsingToolbarLayout. For the layout maybe it's not a good solution but it's smooth. Better ideas are welcome.

Related

Android Fragment RecyclerView Transparent when replace

i just want to replace a fragment by using this code:
fragmentManager.beginTransaction()
.replace(R.id.homepage_fragment_menu, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
the fragment has recyclerview. but when i see the result of fragment, there's no shown of recyclerview. but when i checked in LayoutInspector, it's showed, but invisible like
this
And here's the code when set the adapter on RecyclerView
bookingHistoryProgressBar.setVisibility(View.GONE);
bookingHistoryList.setVisibility(View.VISIBLE);
adapterBookingHistoryList = new AdapterBookingHistoryList(this, bookingHistoryListModels);
bookingHistoryList.setAdapter(adapterBookingHistoryList);
Here's the layout code for RecyclerView and Adapter
XML Fragment Layout
<LinearLayout 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"
android:orientation="vertical"
android:background="#color/grey"
tools:context=".home.bookinghistorypage.BookingHistoryFragment"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="#+id/bookingHistory_listBooking"
android:background="#color/white_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Adapter
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/booking_history_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="6dp"
app:cardElevation="6dp"
android:layout_marginTop="#dimen/margin_small"
android:layout_marginBottom="#dimen/margin_small"
app:cardUseCompatPadding="true">
<LinearLayout
android:background="#color/white"
android:paddingLeft="#dimen/padding_large"
android:paddingRight="#dimen/padding_large"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<helper.CustomFontMontserratBoldTextView
android:id="#+id/booking_history_name"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="3dp"
android:textColor="#color/black"
android:textSize="#dimen/text_medium"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_code"
android:gravity="end"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="#dimen/margin_small"
android:textColor="#color/grey_2"
android:textSize="#dimen/text_medium"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<helper.CustomFontMontserratBoldTextView
android:id="#+id/booking_history_status"
android:background="#color/lightOrange"
android:textColor="#color/black"
android:textSize="#dimen/text_very_small"
android:paddingLeft="#dimen/padding_small"
android:paddingRight="#dimen/padding_small"
android:paddingTop="#dimen/padding_small"
android:paddingBottom="#dimen/padding_small"
android:layout_marginBottom="#dimen/padding_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_marginBottom="#dimen/padding_medium"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#mipmap/ic_tanggal"
android:layout_width="20dp"
android:layout_height="20dp" />
<helper.CustomFontMontserratRegularTextView
android:visibility="gone"
android:id="#+id/booking_history_day_booked"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginLeft="#dimen/margin_small"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_actual_date"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginLeft="#dimen/margin_small"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_time_booked"
android:layout_marginStart="#dimen/margin_medium"
android:layout_marginLeft="#dimen/margin_medium"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
XML Activity (Parent of Fragment)
<com.flipboard.bottomsheet.BottomSheetLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottomsheet"
android:background="#color/black_image_view">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_title_and_description"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/homepage_fragment_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/appbar_layout"
android:layout_above="#id/navigation"
/>
<include
android:id="#+id/navigation"
layout="#layout/element_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ProgressBar
android:id="#+id/homepage_progressBar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
</com.flipboard.bottomsheet.BottomSheetLayout>
AdapterJava
#NonNull
#Override
public BookingHistoryListViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.adapter_booking_history,parent,false);
context = parent.getContext();
return new BookingHistoryListViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final BookingHistoryListViewHolder holder, final int position) {
String data = GetDateUtils.convertEpochToDate(dataList.get(position).getActualDate());
if(dataList.get(position).getBookingStatus().equals("Completed") && dataList.get(position).getFlagRating().equals(false)){
Intent intent = new Intent(holder.itemView.getContext(), ProfessionalRatingActivity.class);
intent.putExtra("professionalId", dataList.get(position).getProfessionalId());
intent.putExtra("expertiseId", dataList.get(position).getExpertiseId());
intent.putExtra("professionalName",dataList.get(position).getProfessionalName());
holder.itemView.getContext().startActivity(intent);
}
if(dataList.get(position).getBookingStatus().equals("OnProcess")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.on_process));
}else if(dataList.get(position).getBookingStatus().equals("Cancel")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.cancelled));
}else if(dataList.get(position).getBookingStatus().equals("Completed")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.completed));
}else if(dataList.get(position).getBookingStatus().equals("Reserved")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.reserved));
}else if(dataList.get(position).getBookingStatus().equals("Reschedule")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.rescheduled));
}else if(dataList.get(position).getBookingStatus().equals("Confirmed")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.confirmed));
}
holder.bookingHistoryName.setText(dataList.get(position).getProfessionalName());
holder.bookingHistoryStatus.setText(dataList.get(position).getBookingStatus());
holder.bookingHistoryDayBooked.setText(dataList.get(position).getDayBooked());
holder.bookingHistoryCode.setText(String.format(Locale.getDefault(),"ID: %s",dataList.get(position).getCode()));
holder.bookingHistoryActualDate.setText(String.format(Locale.getDefault(),"%s",data));
holder.bookingHistoryTimeBooked.setText(String.format(Locale.getDefault(),"# %s",dataList.get(position).getTimeBooked()));
holder.bookingHistoryCardview.setOnClickListener(v -> {
Intent intent = new Intent(v.getContext(), BookingHistoryDetailActivity.class);
intent.putExtra("idProfessionalAdapter", dataList.get(position).getId());
holder.itemView.getContext().startActivity(intent);
});
}
#Override
public int getItemCount() {
return dataList!=null ? dataList.size() :0 ;
}
You're nesting your fragment view in a BottomSheetLayout, and according to the source code, the initial visibility is View.INVISIBLE:
private void init() {
// ...
dimView = new View(getContext()); // Line 150
dimView.setBackgroundColor(Color.BLACK);
dimView.setAlpha(0);
dimView.setVisibility(INVISIBLE);
// ...
}
public void setContentView(View contentView) {
super.addView(contentView, -1, generateDefaultLayoutParams());
super.addView(dimView, -1, generateDefaultLayoutParams());
}
I'm not familiar with Flipboard library, but I've got a feeling that you might be using it incorrectly. Maybe try:
bottomSheetLayout.showWithSheetView(...)
Or please check on their GitHub for usage.
Your recycler view in xml layout has `android:visibility="gone". Remove this line or change it to visible.

in Fragment remove blank space from layout : CollapsingToolbarLayout +NestedScrollView + ViewPager

Problem :
unable to find solution for remove blank space layout
Image :
GIF Image :
Main screen is my HomeFragment in which i use CollapsingToolbarLayout ,NestedScrollView and ViewPager and in ViewPager load 3 Fragments code is below
private void setupViewPager(ViewPager viewPager) {
HomeFragment.ViewPagerAdapter adapter = new HomeFragment.ViewPagerAdapter(getChildFragmentManager());
adapter.addFragment(new InstantFragment(), "Instant");
adapter.addFragment(new LimitFragment(), "Limit");
adapter.addFragment(new StopFragment(), "Stop");
viewPager.setAdapter(adapter);
}
Here is my fragment_home.xml code
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/ll_home_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/ic_app_background">
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top"
app:expandedTitleMarginStart="10dp"
app:expandedTitleMarginTop="20dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:id="#+id/llChild"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="#+id/llview_relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:gravity="center"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinner_currency"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp" />
<Button
android:id="#+id/btndeposit"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="#dimen/margin10"
android:layout_marginRight="#dimen/margin20"
android:background="#color/pink"
android:text="Deposit"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="256dp"
android:layout_margin="#dimen/margin10"
android:layout_marginTop="#dimen/margin10"
android:orientation="vertical"
android:background="#mipmap/ic_app_background">
<com.github.mikephil.charting.charts.CandleStickChart
android:id="#+id/chart1"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:scrollbars="none" />
</LinearLayout>
<TextView
android:id="#+id/txt_my_opn_order"
android:layout_marginTop="#dimen/margin10"
android:text="#string/my_open_orders_title"
android:textSize="17sp"
android:fontFamily="#font/poppins_light"
android:textColor="#color/notification_title"
android:layout_marginLeft="#dimen/margin5"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/sub_frame_container"
android:layout_width="match_parent"
android:visibility="gone"
android:animateLayoutChanges="true"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<TextView
android:layout_marginTop="#dimen/margin10"
android:text="#string/new_orders_title"
android:textSize="17sp"
android:fontFamily="#font/poppins_light"
android:textColor="#color/notification_title"
android:layout_marginLeft="#dimen/margin5"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<com.bacancy.kryptonight.customviews.CustomViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
here is code for CustomViewPager
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height) height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
here is 1st Fragment fragment_instant.xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2C2f33"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="#dimen/margin20"
android:layout_marginTop="#dimen/margin10"
android:gravity="center"
android:text="#string/spend_title"
android:textColor="#color/white"
android:textSize="#dimen/margin20" />
<EditText
android:id="#+id/edtspend"
android:layout_width="match_parent"
android:layout_height="#dimen/edittext_height"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:textColor="#color/white"
android:background="#color/edittext_background"
android:hint="Amount"
android:maxLength="20"
android:inputType="number"
android:paddingLeft="#dimen/margin5" />
<TextView
android:id="#+id/txtsubtotal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_marginTop="#dimen/margin10"
android:visibility="gone"
android:text="#string/subtotal"
android:textColor="#color/textcolor" />
<TextView
android:id="#+id/txtfee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin20"
android:visibility="gone"
android:text="#string/fee"
android:textColor="#color/textcolor" />
<CheckBox
android:layout_margin="#dimen/margin20"
android:id="#+id/chkisPartialBuy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin20"
android:buttonTint="#color/button_buy"
android:text="#string/is_partial_title"
android:textColor="#color/textcolor"
android:textSize="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/approx"
android:textColor="#color/textcolor" />
<TextView
android:layout_marginLeft="#dimen/margin10"
android:id="#+id/txtapprox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="#string/approx_def_price_buy"
android:textColor="#color/textcolor" />
</LinearLayout>
<Button
android:id="#+id/btnbuy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_marginTop="#dimen/margin30"
android:background="#color/button_buy"
android:text="#string/buy"
android:textColor="#color/white" />
<TextView
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="#dimen/margin20"
android:background="#color/line" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="#dimen/margin20"
android:layout_marginTop="#dimen/margin10"
android:gravity="center"
android:text="#string/sell_title"
android:textColor="#color/white"
android:textSize="#dimen/margin20" />
<EditText
android:id="#+id/edtsell"
android:layout_width="match_parent"
android:layout_height="#dimen/edittext_height"
android:layout_marginLeft="#dimen/margin20"
android:textColor="#color/white"
android:inputType="numberDecimal"
android:layout_marginRight="#dimen/margin20"
android:maxLength="20"
android:background="#color/edittext_background"
android:hint="Amount"
android:paddingLeft="#dimen/margin5" />
<TextView
android:id="#+id/txtsubtotal_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_marginTop="#dimen/margin10"
android:text="#string/subtotal"
android:visibility="gone"
android:textColor="#color/textcolor" />
<TextView
android:id="#+id/txtfee_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin20"
android:visibility="gone"
android:text="#string/fee"
android:textColor="#color/textcolor" />
<CheckBox
android:layout_margin="#dimen/margin20"
android:id="#+id/chkisPartialSell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin20"
android:buttonTint="#color/button_sell"
android:text="#string/is_partial_title"
android:textColor="#color/textcolor"
android:textSize="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/approx"
android:textColor="#color/textcolor" />
<TextView
android:id="#+id/txtapprox_sell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin10"
android:maxLines="1"
android:ellipsize="end"
android:text="#string/approx_def_price_sell"
android:textColor="#color/textcolor" />
</LinearLayout>
<Button
android:id="#+id/btnsell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin60"
android:layout_marginLeft="#dimen/margin20"
android:layout_marginRight="#dimen/margin20"
android:layout_marginTop="#dimen/margin30"
android:background="#color/button_sell"
android:text="#string/sell"
android:textColor="#color/white" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
i check CustomViewPager class where height set how can we set height current view to WRAP_CONTENT

RecyclerView not showing up properly (scrunched up)

I've been trying to implement multiple RecyclerView within a layout that is part of a collapsing tab. However, my RecyclerView hasn't been working and I don't know what I did wrong in my code. Please help me!
Here is the Github Link: github.com/arxbombus/RecipeDetails
Here is the desired view: image
Here is what I'm getting for some reason: image
As you can see, everything is all scrunched up. :(
Below I've included the layouts for my MainActivity and also the Java files for my Adapters.
Here is my activity_main.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"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="400dp"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="400dp"
app:title="Some Randome Recipe"
app:titleEnabled="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/ivParallax"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/food"
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"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtAbout"
android:text="About this recipe"
android:textStyle="bold"
android:textSize="13sp"
android:padding="15dp"
android:layout_marginBottom="-25dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtRecipeDescription"
android:text="#string/recipe_description"
android:padding="15dp"
android:layout_marginBottom="-5dp"
android:textSize="12sp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorDivider"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtInfo"
android:text="Info"
android:textStyle="bold"
android:textSize="13sp"
android:padding="15dp"
android:layout_marginBottom="-20dp"
android:layout_marginTop="-5dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvRecipeInfo"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:padding="15dp"></android.support.v7.widget.RecyclerView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorDivider"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtIngredient"
android:text="Ingredients"
android:textStyle="bold"
android:textSize="13sp"
android:padding="15dp"
android:layout_marginBottom="-20dp"
android:layout_marginTop="-5dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvRecipeIngredient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp"></android.support.v7.widget.RecyclerView>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorDivider"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
walking
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtProcedures"
android:text="Procedures"
android:textStyle="bold"
android:textSize="13sp"
android:padding="15dp"
android:layout_marginBottom="-20dp"
android:layout_marginTop="-5dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvRecipeProcedure"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp"></android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
And my CardView
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recipeInfoCards"
android:layout_width="81dp"
android:layout_height="75dp"
app:cardCornerRadius="6dp"
android:elevation="15dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorRecipeInfoCardBG"
android:padding="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/txtRecipeInfoCardTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cooking Time:"
android:textSize="11sp"
android:textColor="#android:color/black"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_marginTop="5dp"
/>
<TextView
android:id="#+id/txtRecipeInfoCardDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="20 Minutes"
android:textSize="11sp"
android:textColor="#color/colorTextSecondary"
android:layout_gravity="center_horizontal"
android:gravity="center"/>
</LinearLayout>
</android.support.v7.widget.CardView>
And here are my MainActivity and Adapters respectiviely
public class MainActivity extends AppCompatActivity {
ArrayList < Recipe > recipeData;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
recipeData = new ArrayList < Recipe > ();
createData();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
RecyclerView recipeInfoCardRV = (RecyclerView) findViewById(R.id.rvRecipeInfo);
recipeInfoCardRV.setHasFixedSize(true);
recipeInfoCardRV.setNestedScrollingEnabled(false);
RecipeInfoAdapter recipeInfoAdapter = new RecipeInfoAdapter(this, recipeData);
recipeInfoCardRV.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
recipeInfoCardRV.setAdapter(recipeInfoAdapter);
RecyclerView recipeIngredientRV = (RecyclerView) findViewById(R.id.rvRecipeIngredient);
recipeIngredientRV.setHasFixedSize(true);
recipeIngredientRV.setNestedScrollingEnabled(false);
recipeIngredientRV.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
RecipeIngredientAdapter recipeIngredientAdapter = new RecipeIngredientAdapter(this, recipeData);
recipeIngredientRV.setAdapter(recipeIngredientAdapter);
}
public void createData() {
ArrayList < RecipeInfoCard > recipeInfoCards = new ArrayList < RecipeInfoCard > ();
recipeInfoCards.add(new RecipeInfoCard("Cooking Time", "20 Minutes"));
recipeInfoCards.add(new RecipeInfoCard("Calories", "3501"));
recipeInfoCards.add(new RecipeInfoCard("Procedures", "Three"));
ArrayList < RecipeIngredient > recipeIngredients = new ArrayList < RecipeIngredient > ();
for (int i = 1; i <= 10; i++) {
recipeIngredients.add(new RecipeIngredient("Ingredient " + i, String.valueOf(i), "grams"));
}
Recipe dm = new Recipe(recipeInfoCards, recipeIngredients);
recipeData.add(dm);
}
}
My adapter for my CardView
public class RecipeInfoAdapter extends RecyclerView.Adapter < RecipeInfoAdapter.RecipeInfoCardItemRowHolder > {
private Context mContext;
private ArrayList < Recipe > recipeData;
public RecipeInfoAdapter(Context mContext, ArrayList < Recipe > recipeData) {
this.mContext = mContext;
this.recipeData = recipeData;
}
#Override
public RecipeInfoCardItemRowHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recipe_info_card_view, null);
return new RecipeInfoCardItemRowHolder(v);
}
#Override
public void onBindViewHolder(RecipeInfoCardItemRowHolder recipeInfoCardItemRowHolder, int position) {
Recipe recipe = recipeData.get(position);
recipeInfoCardItemRowHolder.infoCardTitle.setText(recipe.getRecipeInfoCards().get(position).getRecipeInfoCardTitle());
recipeInfoCardItemRowHolder.infoCardDescription.setText(recipe.getRecipeInfoCards().get(position).getRecipeInfoCardDescription());
}
#Override
public int getItemCount() {
return (null != recipeData ? recipeData.size() : 0);
}
public class RecipeInfoCardItemRowHolder extends RecyclerView.ViewHolder {
protected TextView infoCardTitle;
protected TextView infoCardDescription;
public RecipeInfoCardItemRowHolder(View view) {
super(view);
this.infoCardTitle = (TextView) view.findViewById(R.id.txtRecipeInfoCardTitle);
this.infoCardDescription = (TextView) view.findViewById(R.id.txtRecipeInfoCardDescription);
}
}
}
I didn't put all my code here because I think the question is long enough but I would really appreciate if someone helped me. Thank you!
Try to change your rvRecipeInfo RecyclerView height.. becasue your hardicoading it to 75 dp which is wrong.
<android.support.v7.widget.RecyclerView
android:id="#+id/rvRecipeInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:padding="15dp"></android.support.v7.widget.RecyclerView>
similer to cardview as well
< ?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recipeInfoCards"
android:layout_width="100dp"
android:layout_height="75dp"
app:cardCornerRadius="6dp"
android:elevation="15dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorRecipeInfoCardBG"
android:padding="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/txtRecipeInfoCardTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cooking Time:"
android:textSize="11sp"
android:textColor="#android:color/black"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_marginTop="5dp"
/>
<TextView
android:id="#+id/txtRecipeInfoCardDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="20 Minutes"
android:textSize="11sp"
android:textColor="#color/colorTextSecondary"
android:layout_gravity="center_horizontal"
android:gravity="center"/>
</LinearLayout>
</android.support.v7.widget.CardView>

How to add an ImageView with the title in collapsingtoolbarlayout in Android

I am using CoordinatorLayout to get this effect
Here is the layout code.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinatorRootLayout"
android:background="#android:color/background_light"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/android_appbar_layout"
android:layout_width="match_parent"
android:layout_height="220dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbarLayoutAndroidExample"
android:layout_width="match_parent"
android:background="#fff"
app:collapsedTitleGravity="left"
app:expandedTitleTextAppearance="#color/card_outline"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:expandedTitleGravity="center_horizontal"
app:contentScrim="?attr/colorPrimary"
app:statusBarScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="32dp"
app:expandedTitleMarginEnd="48dp">
<ImageView
android:id="#+id/parallax_header_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/orange_triangle"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.8"/>
<ImageView
app:expandedTitleGravity="center_horizontal"
android:id="#+id/someImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/circle"
android:layout_gravity="center_horizontal"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="-1"
/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="none"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="#+id/linear_layout_android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
android:background="#color/off_white"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="vertical">
<GridView
android:id="#+id/gridview_parallax_header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
and here is what i am getting as output
How can use icon with the title text.
and in Java
mRootLayout = (CoordinatorLayout) findViewById(R.id.coordinatorRootLayout);
mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbarLayoutAndroidExample);
mCollapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.black));
mCollapsingToolbarLayout.setTitle("My App Title");
You can follow this link...
https://github.com/saulmm/CoordinatorBehaviorExample
MainActivity.java
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
implements AppBarLayout.OnOffsetChangedListener {
private static final float PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR = 0.9f;
private static final float PERCENTAGE_TO_HIDE_TITLE_DETAILS = 0.3f;
private static final int ALPHA_ANIMATIONS_DURATION = 200;
private boolean mIsTheTitleVisible = false;
private boolean mIsTheTitleContainerVisible = true;
private LinearLayout mTitleContainer;
private TextView mTitle;
private AppBarLayout mAppBarLayout;
private Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bindActivity();
mAppBarLayout.addOnOffsetChangedListener(this);
mToolbar.inflateMenu(R.menu.menu_main);
startAlphaAnimation(mTitle, 0, View.INVISIBLE);
}
private void bindActivity() {
mToolbar = (Toolbar) findViewById(R.id.main_toolbar);
mTitle = (TextView) findViewById(R.id.main_textview_title);
mTitleContainer = (LinearLayout) findViewById(R.id.main_linearlayout_title);
mAppBarLayout = (AppBarLayout) findViewById(R.id.main_appbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public void onOffsetChanged(AppBarLayout appBarLayout, int offset) {
int maxScroll = appBarLayout.getTotalScrollRange();
float percentage = (float) Math.abs(offset) / (float) maxScroll;
handleAlphaOnTitle(percentage);
handleToolbarTitleVisibility(percentage);
}
private void handleToolbarTitleVisibility(float percentage) {
if (percentage >= PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR) {
if(!mIsTheTitleVisible) {
startAlphaAnimation(mTitle, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
mIsTheTitleVisible = true;
}
} else {
if (mIsTheTitleVisible) {
startAlphaAnimation(mTitle, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
mIsTheTitleVisible = false;
}
}
}
private void handleAlphaOnTitle(float percentage) {
if (percentage >= PERCENTAGE_TO_HIDE_TITLE_DETAILS) {
if(mIsTheTitleContainerVisible) {
startAlphaAnimation(mTitleContainer, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
mIsTheTitleContainerVisible = false;
}
} else {
if (!mIsTheTitleContainerVisible) {
startAlphaAnimation(mTitleContainer, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
mIsTheTitleContainerVisible = true;
}
}
}
public static void startAlphaAnimation (View v, long duration, int visibility) {
AlphaAnimation alphaAnimation = (visibility == View.VISIBLE)
? new AlphaAnimation(0f, 1f)
: new AlphaAnimation(1f, 0f);
alphaAnimation.setDuration(duration);
alphaAnimation.setFillAfter(true);
v.startAnimation(alphaAnimation);
}
}
activity_main.xml
<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"
tools:ignore="RtlHardcoded"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
>
<ImageView
android:id="#+id/main.imageview.placeholder"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerCrop"
android:src="#drawable/quila2"
android:tint="#11000000"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.9"
/>
<FrameLayout
android:id="#+id/main.framelayout.title"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/primary"
android:orientation="vertical"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.3"
>
<LinearLayout
android:id="#+id/main.linearlayout.title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="bottom|center"
android:text="#string/quila_name"
android:textColor="#android:color/white"
android:textSize="30sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
android:text="#string/quila_tagline"
android:textColor="#android:color/white"
/>
</LinearLayout>
</FrameLayout>
</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:scrollbars="none"
app:behavior_overlapTop="30dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardElevation="8dp"
app:contentPadding="16dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8dp"
android:text="#string/lorem"
android:textSize="18sp"
/>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar
android:id="#+id/main.toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/primary"
app:layout_anchor="#id/main.framelayout.title"
app:theme="#style/ThemeOverlay.AppCompat.Dark"
app:title=""
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Space
android:layout_width="#dimen/image_final_width"
android:layout_height="#dimen/image_final_width"
/>
<TextView
android:id="#+id/main.textview.title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:gravity="center_vertical"
android:text="#string/quila_name2"
android:textColor="#android:color/white"
android:textSize="20sp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="#dimen/image_width"
android:layout_height="#dimen/image_width"
android:layout_gravity="center_horizontal"
android:src="#drawable/quila"
app:border_color="#android:color/white"
app:border_width="2dp"
app:finalHeight="#dimen/image_final_width"
app:finalYPosition="2dp"
app:layout_behavior="saulmm.myapplication.AvatarImageBehavior"
app:startHeight="2dp"
app:startToolbarPosition="2dp"
app:startXPosition="2dp"
/>
</android.support.design.widget.CoordinatorLayout>
use
<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"
tools:ignore="RtlHardcoded"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
>
<ImageView
android:id="#+id/main.imageview.placeholder"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerCrop"
android:src="#drawable/quila2"
android:tint="#11000000"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.9"
/>
<FrameLayout
android:id="#+id/main.framelayout.title"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/primary"
android:orientation="vertical"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.3"
>
<LinearLayout
android:id="#+id/main.linearlayout.title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="bottom|center"
android:text="#string/quila_name"
android:textColor="#android:color/white"
android:textSize="30sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
android:text="#string/quila_tagline"
android:textColor="#android:color/white"
/>
</LinearLayout>
</FrameLayout>
</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:scrollbars="none"
app:behavior_overlapTop="30dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardElevation="8dp"
app:contentPadding="16dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8dp"
android:text="#string/lorem"
android:textSize="18sp"
/>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar
android:id="#+id/main.toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/primary"
app:layout_anchor="#id/main.framelayout.title"
app:theme="#style/ThemeOverlay.AppCompat.Dark"
app:title=""
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Space
android:layout_width="#dimen/image_final_width"
android:layout_height="#dimen/image_final_width"
/>
<TextView
android:id="#+id/main.textview.title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:gravity="center_vertical"
android:text="#string/quila_name2"
android:textColor="#android:color/white"
android:textSize="20sp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="#dimen/image_width"
android:layout_height="#dimen/image_width"
android:layout_gravity="center_horizontal"
android:src="#drawable/quila"
app:border_color="#android:color/white"
app:border_width="2dp"
app:finalHeight="#dimen/image_final_width"
app:finalYPosition="2dp"
app:layout_behavior="saulmm.myapplication.AvatarImageBehavior"
app:startHeight="2dp"
app:startToolbarPosition="2dp"
app:startXPosition="2dp"
/>
</android.support.design.widget.CoordinatorLayout>
for more info: https://github.com/saulmm/CoordinatorBehaviorExample

CollapsingToolbarLayout set animation threshold?

In my application when I start scrolling the layout, the CollapsingToolbarLayout starts almost immediately changing the background to the scrim color I set.
Is there a way to set the value at which the CollapsingToolbar starts to change the background?
This is my XML layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="eu.ericnisoli.ambrosettiap.activities.MeetingActivity"
android:visibility="visible"
android:id="#+id/container">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:fitsSystemWindows="true"
android:layout_height="#dimen/app_bar_height"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:titleEnabled="false">
<RelativeLayout
android:id="#+id/relativeLayout_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
app:layout_collapseMode="parallax">
<FrameLayout
android:id="#+id/frameLayout_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/frameLayout_info">
<ImageView
android:id="#+id/imageView_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/login_bg"
android:scaleType="centerCrop"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/detail_meeting_gradient" />
<LinearLayout
android:id="#+id/linearLayout_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingEnd="80dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:layout_gravity="bottom">
<TextView
android:id="#+id/textView_meeting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="#string/meeting"
android:textColor="#color/text_grey_1"
android:textSize="#dimen/text_size_14"
android:textAllCaps="true"
/>
<TextView
android:id="#+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="#dimen/text_size_16"
android:text="New Text"
/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="#+id/frameLayout_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/grey_2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="32dp"
android:paddingBottom="32dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/pin_small_icon"
android:layout_marginBottom="4dp"/>
<TextView
android:id="#+id/textView_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/text_black_1"/>
<TextView
android:id="#+id/textView_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/text_black_1"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="32dp"
android:paddingBottom="32dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cal_small_icon"
android:layout_marginBottom="4dp"/>
<TextView
android:id="#+id/textView_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/text_black_1"/>
<TextView
android:id="#+id/textView_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/text_black_1"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:title="#string/event_caps"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_anchor="#+id/app_bar"
app:layout_anchorGravity="bottom"
app:layout_collapseMode="pin">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:layout_anchor="#+id/app_bar"
app:layout_anchorGravity="bottom"
android:background="#color/grey_2"
app:tabTextColor="#color/text_black_1"
app:tabSelectedTextColor="#color/text_black_1"
style="#style/DetailTab"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#drawable/shadow"
android:layout_gravity="bottom"/>
</FrameLayout>
<android.support.v4.view.ViewPager
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_marginTop="?attr/actionBarSize"/>
<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/frameLayout_title"
app:layout_anchorGravity="bottom|end"/>
</android.support.design.widget.CoordinatorLayout>
<ProgressBar
android:id="#+id/progress"
android:layout_width="48dp"
android:layout_height="48dp"
android:indeterminate="true"
android:layout_gravity="center"
android:visibility="gone"/>
</FrameLayout>
With version 26.1 or newer, you can use the scrimVisibleHeightTrigger attribute to set the height threshold when to show the scrim overlay.
<android.support.design.widget.CollapsingToolbarLayout
app:scrimVisibleHeightTrigger="80dp"
...>
Set the amount of visible height in pixels used to define when to trigger a scrim visibility change.
If the visible height of this view is less than the given value, the scrims will be made visible, otherwise they are hidden.
Dry
After looking into CollapsingToolbarLayout's implementation, you may see, that content scrim is appearing when CollapsingToolbarLayout height gets lower than its minimum height x 2 + "status bar height":
if (mContentScrim != null || mStatusBarScrim != null) {
setScrimsShown(getHeight() + verticalOffset < getScrimTriggerOffset() + insetTop);
}
and here is getScrimTriggerOffset implementation:
final int getScrimTriggerOffset() {
return 2 * ViewCompat.getMinimumHeight(this);
}
Unfortunately setting minHeight property won't work, because this piece of code will overwrite it during onLayout:
if (mToolbarDirectChild == null || mToolbarDirectChild == this) {
setMinimumHeight(getHeightWithMargins(mToolbar));
} else {
setMinimumHeight(getHeightWithMargins(mToolbarDirectChild));
}
Solution
Extend CollapsingToolbarLayout and after onLayout call setMinimumHeight. You may also use the following implementation with setContentScrimHeight method:
import android.content.Context;
import android.support.design.widget.CollapsingToolbarLayout;
import android.util.AttributeSet;
public class MyCollapsingToolbarLayout extends CollapsingToolbarLayout {
private int contentScrimHeight;
public MyCollapsingToolbarLayout(Context context) {
super(context);
}
public MyCollapsingToolbarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyCollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
super.setMinimumHeight(contentScrimHeight);
}
public int getContentScrimHeight() {
return contentScrimHeight;
}
public void setContentScrimHeight(int contentScrimHeight) {
this.contentScrimHeight = contentScrimHeight;
requestLayout();
}
}
Use setParallaxMultiplier(float) on view's layout parameters with id relativeLayout_title.
setParallaxMultiplier changes the threshold at which parallax animation starts triggering. By default it triggers at half the parent height, equivalent of setting the value of 0.5f.
Source

Categories

Resources