<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:background="#color/divider"
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/wall"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerCrop"
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="150dp"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="0dp"
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:layout_marginTop="0dp"
android:orientation="vertical">
<TextView
android:id="#+id/profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="bottom|center"
android:text="Amit Kumar yadav"
android:textColor="#android:color/white"
android:textSize="24sp"/>
<TextView
android:id="#+id/profile_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="2dp"
android:text="#string/quila_tagline"
android:textColor="#android:color/white"/>
<LinearLayout
android:layout_marginTop="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:scaleType="fitEnd"
android:src="#drawable/ic_love"/>
<TextView
android:id="#+id/relationship"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Single"
android:textSize="12dp"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-20dp"
android:scrollbars="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.CardView
android:id="#+id/cardProfileRates"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="8dp">
// 2-3 linear layout
</android.support.v7.widget.CardView>
<LinearLayout
android:id="#+id/userInfo"
android:layout_below="#id/cardProfileRates"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// 2-3 linear layout
</LinearLayout>
<LinearLayout
android:id="#+id/userPhotos"
android:layout_below="#+id/userInfo"
android:layout_marginTop="10dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white"
android:padding="10dp"
>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_below="#+id/userPhotos"
android:id="#+id/user_posts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar
android:id="#+id/main_toolbar99"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
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/profile_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:id="#+id/profilePic"
android:layout_width="#dimen/image_width"
android:layout_height="#dimen/image_width"
android:layout_gravity="center_horizontal"
android:src="#drawable/face"
app:civ_border_color="#android:color/white"
app:civ_border_width="1dp"
app:finalHeight="#dimen/image_final_width"
app:finalYPosition="2dp"
app:layout_behavior="in.fabits.fabits.AvatarImageBehavior"
app:startHeight="2dp"
app:startToolbarPosition="2dp"
app:startXPosition="2dp"/>
</android.support.design.widget.CoordinatorLayout>
The problem is that when i open this activity every thing above recyclerview i.e., (1 cardview and 2 LinearLayout) are pushed up and only recyclerview is showing by default.
To see my cardview and linearlayout i have to scrollup to see i.e, recyclerview is getting somehow focus by default.
I have also tried
recyclerView.setNestedScrollingEnabled(false);
ViewCompat.setNestedScrollingEnabled(recyclerView, false);
but it makes no change.
so i trying to get cardview visible(or on focus) because it is above recyclerview is that possible
There is no meaning of putting one Scrollable view into another. If you are going with recyclerview, you can consider different item_type to add into recyclerview. There are plenty of tutorials available on Internet.
This is one of 'em - Heterogenous-Layouts-inside-RecyclerView
Related
I'm adding a BottomNavigationView to My MainActivity
at first show nothing wrong but after click on other items, BottomNavigationView strangely moving up and down. In other projects, I had never this problem and I don't know why I am getting this:
p.s: In default fragment (which is first at right in screenshot) I have a content but in other fragments, I have no content.
Here is my MainActivity layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="com.activity.MainActivity">
<FrameLayout
android:id="#+id/MainActivity_FrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/MainActivity_BottomView" />
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
app:menu="#menu/main_bottom_view_menu"
app:elevation="2dp"
app:itemTextColor="#android:color/white"
app:itemIconTint="#android:color/white"
android:id="#+id/MainActivity_BottomView"/>
</RelativeLayout>
and here is the screenshot of how does shown
after clicking on another item
and when select default item again
--- EDIT ---
I realized it's happen when use CoordinatorLayout , AppBarLayout and CollapsingToolbarLayout in fragment . After remove that lines app work without any problem .
Here is my fragment Layout :
<android.support.design.widget.CoordinatorLayout 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:background="#e2e2e2"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.fragment.MainFragments.ProfileFragment">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:background="#color/colorPrimaryDark"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimaryDark"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false"
app:scrimAnimationDuration="300"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:background="#color/colorPrimaryDark"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="140dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:id="#+id/Profile_InfoContainer"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content">
<com.graymind.applog.customview.CircleImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="#+id/Profile_ProfilePhoto"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
app:srcCompat="#drawable/login_bg"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:textColor="#android:color/white"
android:gravity="center"
android:id="#+id/Profile_FullName"
android:text="FullName"
android:textStyle="bold"/>
<TextView
android:id="#+id/Profile_Id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="'#gray_mind75"
android:textColor="#android:color/white"
android:textStyle="normal" />
</LinearLayout>
<TextView
android:id="#+id/Profile_Bio"
android:layout_width="match_parent"
android:layout_below="#+id/Profile_InfoContainer"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:layout_marginBottom="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textSize="12sp"
android:lineSpacingExtra="4sp"/>
android:textColor="#android:color/white"
android:textDirection="rtl" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="3"
android:layout_below="#+id/Profile_Bio"
android:layout_height="50dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:weightSum="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="1234"
android:textColor="#android:color/white"
android:textSize="#dimen/profile_stats_texts_size"
android:gravity="center"
tools:ignore="NestedWeights" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:textSize="#dimen/profile_stats_texts_size"
android:textColor="#android:color/white"
android:gravity="center"
android:text="#string/post"/>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:weightSum="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="1234"
android:textSize="#dimen/profile_stats_texts_size"
android:textColor="#android:color/white"
android:gravity="center"
tools:ignore="NestedWeights" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:textColor="#android:color/white"
android:textSize="#dimen/profile_stats_texts_size"
android:gravity="center"
android:text="#string/followings"/>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp"
android:weightSum="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="1234"
android:textSize="#dimen/profile_stats_texts_size"
android:textColor="#android:color/white"
android:gravity="center"
tools:ignore="NestedWeights" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:textSize="#dimen/profile_stats_texts_size"
android:textColor="#android:color/white"
android:gravity="center"
android:text="#string/followers"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
app:layout_collapseMode="pin"
android:layout_height="?attr/actionBarSize">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/profile"
android:gravity="center"
android:layout_toStartOf="#+id/Profile_ToolbarProfileIcon"
android:textColor="#android:color/white"
android:layout_marginEnd="10dp"/>
<ImageView
android:layout_width="30dp"
android:layout_marginEnd="10dp"
android:padding="5dp"
android:id="#+id/Profile_ToolbarProfileIcon"
android:layout_height="match_parent"
app:srcCompat="#drawable/ic_profile"
android:tint="#android:color/white"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/ProfilePostsScrollView"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:requiresFadingEdge="none"
android:id="#+id/Profile_PostsRecycler"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Thanks in advance for your guidance.
Change your root layout to LinearLayout like below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="com.activity.MainActivity">
<FrameLayout
android:id="#+id/MainActivity_FrameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:menu="#menu/main_bottom_view_menu"
app:elevation="2dp"
app:itemTextColor="#android:color/white"
app:itemIconTint="#android:color/white"
android:id="#+id/MainActivity_BottomView" />
</LinearLayout>
I'm facing this problem that I want to replace the CardView in CoordinatorLayout in specific location like first photo
but when I center the CardView using layout_gravity= "center" the view will be like second photo
I need to position the card view like in first photo .. how could I do that ??
this is my 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bgColorPrimaryBlue"
android:orientation="vertical"
tools:context="****">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="250dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradiant_background"
app:collapsedTitleGravity="center"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="exitUntilCollapsed|scroll">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="#dimen/profile_image_height"
android:layout_height="#dimen/profile_image_height"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#drawable/worker"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<TextView
android:id="#+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/el_messiri"
android:paddingTop="140dp"
android:text="User name"
android:textSize="25sp"
android:textStyle="bold"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<TextView
android:id="#+id/user_job"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/el_messiri"
android:paddingTop="175dp"
android:text="Desc"
android:textSize="20sp"
android:textStyle="bold"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<android.support.v7.widget.Toolbar
android:id="#+id/profile_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/Base.ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.CardView
android:layout_width="300dp"
android:layout_height="70dp"
android:layout_gravity="center"
app:cardBackgroundColor="#color/bgColorPrimaryBlue">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_thumb_up_black"
android:text="123"
android:textColor="#color/colorPrimaryBlue"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_thumb_down_black_24px"
android:text="123"
android:textColor="#color/colorPrimaryBlue"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_block_black_24px"
android:text="123"
android:textColor="#color/colorPrimaryBlue"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.design.widget.CoordinatorLayout>
Thanks in advance
Try this
<?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:background="#color/colorAccent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="250dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:collapsedTitleGravity="center"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="exitUntilCollapsed|scroll">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#drawable/abc"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<TextView
android:id="#+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="140dp"
android:text="User name"
android:textSize="25sp"
android:textStyle="bold"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<TextView
android:id="#+id/user_job"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="175dp"
android:text="Desc"
android:textSize="20sp"
android:textStyle="bold"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<android.support.v7.widget.Toolbar
android:id="#+id/profile_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/Base.ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.CardView
android:layout_width="300dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:layout_marginTop="220dp"
app:cardBackgroundColor="#color/colorPrimaryDark"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_launcher_background"
android:text="123"
android:textColor="#color/colorPrimaryDark"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_launcher_background"
android:text="123"
android:textColor="#color/colorPrimaryDark"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_launcher_background"
android:text="123"
android:textColor="#color/colorPrimaryDark"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.design.widget.CoordinatorLayout>
OUTPUT
I solved the problem by using minus value for top margin in nestedScrollView
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-35dp"
app:layout_anchorGravity="top"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<!--CardView and all of it's childs-->
</android.support.v4.widget.NestedScrollView>
and centered the card view programmatically using this
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int width = displayMetrics.widthPixels;
final int cardMarginLeft = (width - cardView.getLayoutParams().width) / 2;
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) cardView.getLayoutParams();
layoutParams.leftMargin = cardMarginLeft;
may be there is better approaches to solve this .. but this one worked for me .
I am using a CollapsingToolbarLayout for a collapsing tool bar and it works for the most part. When you start scrolling on any part of the page besides the RecyclerView it will scroll fine and the toolbar will collapse like it should. However when you do start scrolling on the RecyclerView it doesn't collapse the tool bar and doesn't look the best.
I've tried a lot of different solutions I've found online and none have seemed to help. I'm using appcompat-v7:23.2.1. Here's what the layout file looks like:
<?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.support.design.widget.AppBarLayout
android:id="#+id/movie_detail_app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/movie_detail_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/movie_detail_backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:contentDescription="#string/cd_backdrop"/>
<android.support.v7.widget.Toolbar
android:id="#+id/movie_detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- Movie Content here -->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:padding="16dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/movie_detail_out_yet_layout"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_width="20dp"
android:layout_height="20dp"
tools:background="#drawable/green_square">
<ImageView
android:id="#+id/movie_detail_out_yet_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:src="#drawable/ic_checkmark"/>
</RelativeLayout>
<TextView
android:layout_toRightOf="#+id/movie_detail_out_yet_layout"
android:layout_toEndOf="#+id/movie_detail_out_yet_layout"
android:id="#+id/movie_detail_release_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/textAppearanceMedium"
tools:text="March 21, 2016"/>
<TextView
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:id="#+id/movie_detail_mpaa_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/textAppearanceMedium"
android:textStyle="bold"
tools:text="PG-13"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<TextView
android:layout_marginTop="16dp"
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/h_plot"/>
<TextView
android:layout_marginTop="5dp"
android:id="#+id/movie_detail_plot"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_marginTop="16dp"
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/h_ratings"/>
<TextView
android:id="#+id/movie_detail_no_ratings_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/unknown"
android:visibility="gone"/>
<LinearLayout
android:orientation="horizontal"
android:id="#+id/movie_detail_rating_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Critics Section -->
<LinearLayout
android:layout_weight="0.5"
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/movie_detail_critics_rating_box"
android:layout_marginTop="5dp"
tools:background="#drawable/orange_square"
tools:text="6.7"
android:textColor="#android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_gravity="center_vertical"
android:id="#+id/movie_detail_critics_rating_tv"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/textAppearanceMedium"
android:text="#string/critics_rating"/>
</LinearLayout>
<!-- Audience Section -->
<LinearLayout
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/movie_detail_audience_rating_box"
android:layout_marginTop="5dp"
tools:background="#drawable/orange_square"
tools:text="6.7"
android:textColor="#android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/textAppearanceMedium"
android:text="#string/audience_rating"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_marginTop="16dp"
style="?android:listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/h_cast"/>
<TextView
android:id="#+id/movie_detail_no_cast_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
style="?android:textAppearanceMedium"
android:text="#string/unknown"
android:visibility="visible"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/movie_detail_cast_member_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:visibility="gone"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
For the RecyclerView, I set it to have a LinearLayoutManager and to my custom adapter. Any help would be great, it's been a couple weeks and I still haven't been able to figure this out.
Edit: It appears to only happen when scrolling up. If the tool bar is collapsed and I scroll down, it does expand like it should. However, as before, when scrolling up it doesn't seem to work.
I am new to CollapsingToolbarLayout when i scroll my content was not scroll smoothly any one please help where i did wrong were below my layout,when i scrooll up it my layout was not scrolling smoothly
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp" >
<ImageView
android:id="#+id/fulldec_image"
android:layout_width="match_parent"
android:layout_height="350dp"
android:scaleType="fitXY"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_gravity="bottom">
<TextView
android:id="#+id/fulldectext"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_gravity="center"
android:text="The problem is not the problem. The problem is your attitude about the problem"
android:textSize="25sp"
android:lineSpacingMultiplier="1.2"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/fullde_descriptiontect"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:text="Hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="20dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="130dp"
android:paddingLeft="30dp"
android:background="#FFFFFF"
android:orientation="vertical">
<TextView
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:text="More Links"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:textStyle="bold"
android:textSize="15dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_one_t"
android:gravity="center"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView
android:id="#+id/text_two_t
android:layout_marginTop="10dp"
android:textSize="20dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
I am using a CoordinatorLayout with RecyclerView.The app runs fine but my problem is the the view should only scroll as the items in RecyclerView.In my case i have only 3 items but the CordinatorLayout will scroll the RecyclerView till it will snap to the top because of this i am getting the below part as white as the listsize is only 3.
XMl
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView38"
android:layout_alignParentTop="true"
android:padding="20dp"
android:src="#drawable/ic_filter_back" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_event_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#fff"
android:orientation="horizontal"
android:paddingBottom="03dp">
<RelativeLayout
android:id="#+id/rl_tab1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="#+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="05dp"
android:src="#drawable/ic_create_wedding_admin" />
<TextView
android:id="#+id/tv_tab_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tab1"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:gravity="center"
android:text="Admin" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_tab2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="#+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="05dp"
android:src="#drawable/ic_create_wedding_guests" />
<TextView
android:id="#+id/tv_tab_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tab2"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:gravity="center"
android:text="Guests" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_ed_tab_guests"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="#+id/iv_ed_iv_budget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="05dp"
android:src="#drawable/ic_create_wedding_budget" />
<TextView
android:id="#+id/tvbud"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iv_ed_iv_budget"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:gravity="center"
android:text="Budget" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_ed_tab_tasks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="#+id/iv_ed_iv_tasks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="05dp"
android:src="#drawable/ic_create_wedding_tasks" />
<TextView
android:id="#+id/tv_ed_tasks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iv_ed_iv_tasks"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:gravity="center"
android:text="Tasks" />
</RelativeLayout>
</LinearLayout>
What i want is to scroll the view only till the item size.
This issue has already been brought up.
Please check other questions before posting another.
You need to provide a custom behavior to your child layout in the Coordinator Layout.
Check this if it helps:
https://stackoverflow.com/a/33461064/2346980