Recycler view items are not scrolling? - android

I am working on Recycler view and here i placed the three recycler views in a row horizontally in a layout.The issue is second and third recycler view items are displayed but cannot able to scroll even though using nested scroll inside and hereby attached xml.Kindly suggest me how to make scroll the second and third recycler view.
<RelativeLayout
android:id="#+id/layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#color/color_bottom_sheet"
android:elevation="#dimen/z_bottom_sheet"
app:behavior_hideable="true"
app:behavior_peekHeight="80dp"
app:layout_behavior="#string/string_bottom_sheet_behavior">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rightLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/lay1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewmonth"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true"
android:verticalScrollbarPosition="right">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/lay2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00ff00">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewdate"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="#+id/lay3"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000ff">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewyear"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/text_view_sheet_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/activity_vertical_margin"
android:text="#string/text_pull_to_show_more"
android:textSize="#dimen/text_size_medium"
android:visibility="gone" />
<TextView
android:id="#+id/text_view_more_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text_view_sheet_title"
android:paddingLeft="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_vertical_margin"
android:text="#string/text_more_contet_to_user"
android:textSize="#dimen/text_size_big"
android:textStyle="bold"
android:visibility="gone" />
<Button
android:id="#+id/btnclick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/text_view_more_content"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:layout_marginRight="#dimen/activity_vertical_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:text="#string/text_click_me"
android:visibility="gone" />
</RelativeLayout>
//Java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerViewmonth);
RecyclerView recyclerdate = (RecyclerView) findViewById(R.id.recyclerViewdate);
RecyclerView recycleryear = (RecyclerView) findViewById(R.id.recyclerViewyear);
ButterKnife.bind(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
LinearLayoutManager linearLayoutManagerdate = new LinearLayoutManager(getApplicationContext());
LinearLayoutManager linearLayoutManageryear = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(linearLayoutManager);
recyclerdate.setLayoutManager(linearLayoutManagerdate);
recycleryear.setLayoutManager(linearLayoutManageryear);
recyclerView.setNestedScrollingEnabled(false);
recyclerdate.setNestedScrollingEnabled(false);
recycleryear.setNestedScrollingEnabled(false);
for (int i = 0; i <= 31; i++) {
dayList.add(String.valueOf(i));
}
CustomAdapter customAdapter = new CustomAdapter(MainActivity.this, monthList);
recyclerView.setAdapter(customAdapter);
DayAdapter dayAdapter=new DayAdapter(MainActivity.this,dayList);
recyclerdate.setNestedScrollingEnabled(false);
recyclerdate.setAdapter(dayAdapter);
recyclerdate.setNestedScrollingEnabled(false);
YearAdapter yearAdapter=new YearAdapter(MainActivity.this,monthList);
recycleryear.setAdapter(yearAdapter);

Post your java code also where you are initializing the recycler views. Also, Try to remove the recycler view from the nested scroll view (you can place them without nested scroll view )
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rightLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/lay1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewmonth"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/lay2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00ff00">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewdate"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/lay3"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000ff">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewyear"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>

Keep all the Recycler views inside the Nested Scroll View.

Change your parent layout height to match_parent. Like
<RelativeLayout
android:id="#+id/layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/color_bottom_sheet"
android:elevation="#dimen/z_bottom_sheet"
app:behavior_hideable="true"
app:behavior_peekHeight="80dp"
app:layout_behavior="#string/string_bottom_sheet_behavior">
</RelativeLayout>

Related

Android dynamically add cardview into horizontal scroll view

I'm trying to add dynamically cardviews into horizontal scroll view so that I have as many cardviews as I have rows in the database. I have defined cardview in a separated XML file.
But I can't add the cardview into the layout in my main activity as the cardview is null. Is the problem in adding an element from a different file? Should I rather define the cardview in code? Or should I use RecyclerView instead?
I searched a lot but nothing helped yet.
Here is my main activity.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout scroll = findViewById(R.id.layout_horizontal_theme);
CardView cardView = findViewById(R.id.theme_cardview);
scroll.addView(cardView);
}
XML file for card view
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:contentDescription="#string/card"
android:minHeight="150dp"
app:cardBackgroundColor="#FF402D"
app:cardCornerRadius="16dp"
android:id="#+id/theme_cardview">
<!-- app:cardElevation="10dp"-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:id="#+id/layout_theme_card">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:contentDescription="#string/card_image"
android:cropToPadding="true"
android:maxWidth="100dp"
android:src="#drawable/android_developer" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:contentDescription="#string/card_theme"
android:text="#string/card_theme"
android:textColor="#color/Not_so_white_white"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
And XML for main activity
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:layout_gravity="center">
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:layout_constraintBottom_toTopOf="#+id/horizontalScrollView"
app:layout_constraintEnd_toEndOf="#id/guideline2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#id/guideline"
app:layout_constraintTop_toTopOf="parent">
<include layout="#layout/progress_bar" />
</RelativeLayout>
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/list_scroll"
android:fillViewport="true"
app:layout_constraintBottom_toTopOf="#+id/horizontalScrollView2"
app:layout_constraintEnd_toEndOf="#id/guideline2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#id/guideline"
app:layout_constraintTop_toBottomOf="#+id/relativeLayout">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="#+id/layout_horizontal_diff">
<include layout="#layout/difficulty_card" />
<include layout="#layout/difficulty_card" />
<include layout="#layout/difficulty_card" />
<include layout="#layout/difficulty_card" />
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:id="#+id/horizontalScrollView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/list_scroll_2"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/horizontalScrollView"
app:layout_constraintVertical_bias="0.503">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="#+id/layout_horizontal_theme">
<!-- <include layout="#layout/theme_card" />
<include layout="#layout/theme_card" />
<include layout="#layout/theme_card" />
<include layout="#layout/theme_card" />-->
</LinearLayout>
</HorizontalScrollView>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.10" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.90" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navDrawer"
android:layout_height="match_parent"
android:layout_width="wrap_content"
app:headerLayout="#layout/navigation_drawer"
app:menu="#menu/nav_drawer_menu"
android:layout_gravity="start"
android:fitsSystemWindows="true"/>
</androidx.drawerlayout.widget.DrawerLayout>
Thank you all for your help:)
You need to inflate your card view and then you can use it for any purpose:
View view = View.inflate(this, R.layout.cardview_layout, null);
You can then cast it to CardView
CardView cardView = (CardView) View.inflate(this, R.layout.cardview_layout, null);
Your code will look like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout scroll = findViewById(R.id.layout_horizontal_theme);
CardView cardView = (CardView) View.inflate(this, R.layout.cardview_layout, null);
scroll.addView(cardView);
}
follow the example to create custom view. After that, create
your custom view and put them to horizontal view.
CardView cardView = findViewById(R.id.theme_cardview); alway return null.

Two recycleviews in one activity scroll problem

I have created 2 recycleviews in one activity. One scrolls horizontally while other scrolls vertically. I can scroll correctly inside each RecyclerView but the page as a whole won't scroll i.e. top RecyclerView stays at the top always and bottom one stays at the bottom like both are fixed in position.
<ScrollView
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.shakeelnawaz.recipes.AllRecipesFragmet">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/trending_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/horizontaltrendingrecycleview"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginStart="15dp"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/all_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
I read this post "Scolling with multiple RecyclerViews in Layout" and set vertical recycleview's height programmatically. like this
LinearLayout.LayoutParams params = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
// calculate height of RecyclerView based on child count
params.height=1150;
// set height of RecyclerView
recyclerView.setLayoutParams(params);
But the problem is that how I can calculate the height of RecyclerView based on child count?
Use NestedScrollView instead of ScrollView
and use this below line in your Fragment in Activity.
ViewCompat.setNestedScrollingEnabled(mYourRecycleView, false);
This will be work on all your Android API level.
Replace ScrollView with NestedScrollView
Then add: horizontaltrendingrecycleview.isNestedScrollingEnabled = false
Your XML should look like below:
<android.support.v4.widget.NestedScrollView
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:fillViewport="true"
tools:context="com.shakeelnawaz.recipes.AllRecipesFragmet">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/trending_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/horizontaltrendingrecycleview"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginStart="15dp"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/all_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

How to scroll other views with recyclerView in android?

I have layout having RecyclerView with 5 TextViews and NestedScrollView is a parent layout. So I need to scroll all 5 TextViews with RecycleView. As per current implementation only RecycleView is scrolling. Please tell me how do i achieve this? My XML is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:focusableInTouchMode="true"
app:layout_behavior="com.evs.demo.layout.FixedScrollingViewBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/ToolBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_deep_orange_500"
android:elevation="8dp"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:scrollbars="vertical" />
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="No Records" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="No Records" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="No Records" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="No Records" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="No Records" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
For proper scrolling you can change the layout manager you have set in coding for recycler view. I hope it helps.
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity()) {
#Override
public boolean canScrollVertically() {
return false;
}
};
recyclerView.setLayoutManager(layoutManager);
Another solution
try below codes:
RecyclerView recycleView = (RecyclerView) findViewById(R.id.lastest_product_list);
recycleView.setNestedScrollingEnabled(false);
You can modify your layout
<ScrollView>
<LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/lastest_product_list"
android:nestedScrollingEnabled="false"
android:isScrollContainer="false">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Please make the height of your recycler view to "wrap_content" instead of "0dp". This will make the recycler view takes its own height and it scrolls seamlessly with the parent Nested Scroll View.
You should add 5 TextView inside Recyclerview. And 5 TextView is another view type of Recyclerview. You can follow this article to add footer type to Recyclerview.
http://takeoffandroid.com/android-customview/header-and-footer-layout-for-recylerview/

Collapsing ToolBar Layout with viewpager

I am using CollapsingBarLayout with viewpager and the fragments of viewpager are having listview, gridview.
Here 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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bigsteptech.seandroidnativeapp.classes.modules.common.ViewGroupEvent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android: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:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="#style/TransparentText">
<FrameLayout
android:id="#+id/carouselLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax">
<ImageView
android:id="#+id/coverImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="bottom"
android:orientation="vertical"
android:layout_gravity="bottom"
android:padding="#dimen/profile_image_margin"
android:background="#drawable/gradient_bg"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/profile_image_margin"
android:textSize="#dimen/text_size_xlarge"
android:textStyle="bold"
android:textColor="#color/white"
android:id="#+id/content_title"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginLeft="#dimen/profile_image_margin"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="#dimen/text_size_medium"
android:id="#+id/category_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_toRightOf="#+id/category_title"
android:layout_marginLeft="#dimen/profile_image_margin"
android:textColor="#color/white"
android:textSize="#dimen/text_size_medium"
android:id="#+id/memberCount"/>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="#style/ActionBarThemeOverlay"
app:popupTheme="#style/ActionBarPopupThemeOverlay"
android:background="#drawable/gradient_bg"
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:layout_gravity="fill_vertical"
android:isScrollContainer="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contentInfo"
android:paddingBottom="48sp"
android:clipToPadding="false"
android:orientation="vertical">
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/profile_page_left_right_margin"
android:layout_gravity="center"
android:id="#+id/progressBar"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#color/grey_light">
<TextView android:id="#+id/ownerTitle"
android:clickable="true"
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/keyline_1"
android:layout_gravity="center_vertical"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/body_text_1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/profile_image_margin"
android:padding="10dp">
<com.bigsteptech.seandroidnativeapp.Classes.Modules.Common.ViewRelated.ExpandableTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/keyline_1"
style="#style/TextBody"
android:layout_gravity="center_vertical"
android:id="#+id/view_description" />
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="#+id/slidingTabs"
android:layout_width="match_parent"
app:tabIndicatorHeight="3dp"
app:tabMode="scrollable"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="300dp">
</android.support.v4.view.ViewPager>
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="#id/appbar"
android:id="#+id/joinGroupButton"
app:layout_anchorGravity="bottom|right|end"
android:src="#drawable/ic_action_new"
android:layout_margin="#dimen/fab_margin"
android:clickable="true"/>
</android.support.design.widget.CoordinatorLayout>
The fragments which are having listview, gridview do not scroll to up in collapsing toolBar, how can I achieve this working..
Please help me, thank you so much in advanced...
You need put your ViewPager inside AppBar section and setup layout_behavior :
<android.support.design.widget.AppBarLayout>>
<android.support.design.widget.CollapsingToolbarLayout>
// THIS VIEWS WILL BE COLLAPSED
</android.support.design.widget.CollapsingToolbarLayout>
// THIS VIEWS WILL BE PINNED
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</android.support.design.widget.AppBarLayout>
If you using Fragments as children of ViewPager you need setup layout_behavior to each fragment inside ViewPager too.
app:layout_behavior="#string/appbar_scrolling_view_behavior"
collapsing toolbar with tabs using new material design support library
I used official collapsing toolbar feature of new material design support library.
here collapsed view height is 256dp and tabs height is 56dp
i made following path
i cut image into two parts one for collapsed view and one for tabs.
i cutted images according to dp to pixel sizes with high resolution drawable xxxhdpi and put into drawable folder so it will adjustable to all screen sizes
i have 2000x1246 image
top image 256dp= 2000x1024 pixel
bottom tab image 56dp= 2000x224 pixel
Here is the complete example with source code
ListView and GridView are not equipped with NestedScrolling functions. And thats needed to work with the CollapsingToolbarLayout.
The easiest way to make it work, would be to change your ListView and GridView to RecyclerViews (RecyclerView implements NestedScrollingChild).
i have achieved this i will put my code with the library used
firstly this is the layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/attraction_lay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f6f5">
<RelativeLayout
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="47dp">
<TextView
android:id="#+id/exp_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:text="See & do"
android:textColor="#1b7bba"
android:textSize="17sp" />
<RelativeLayout
android:id="#+id/relmenu"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<ImageView
android:layout_width="17dp"
android:layout_height="14dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="17dp"
android:layout_marginLeft="8dp"
android:src="#drawable/menu_icon_blue" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relsearch"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true">
<ImageView
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="17dp"
android:layout_marginRight="8dp"
android:src="#drawable/search_icon_blue" />
</RelativeLayout>
</RelativeLayout>
<View
android:id="#+id/div"
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_below="#+id/bar"
android:background="#1b7bba" />
<FrameLayout
android:id="#+id/layout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/div">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:divider="#null"
android:focusable="false"
android:focusableInTouchMode="false"
android:listSelector="#android:color/transparent"
android:scrollbars="none" />
<FrameLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="290dp"
android:layout_marginTop="0dp"
android:orientation="vertical">
<FrameLayout
android:id="#+id/images_header"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:layout_marginBottom="40dp">
<android.support.v4.view.ViewPager
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:overScrollMode="never" />
<RelativeLayout
android:id="#+id/gallery_back"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_gravity="left|center_vertical">
<ImageView
android:layout_width="20dp"
android:layout_height="52dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/arrow_back" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/gallery_next"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_gravity="right|center_vertical">
<ImageView
android:layout_width="20dp"
android:layout_height="52dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/arrow_next" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="-150dp"
android:layout_marginTop="170dp"
android:background="#drawable/horizontal_gradient" />
<TextView
android:id="#+id/pagenum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:text="3/15"
android:textColor="#FFF"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/header_text_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/min_height_textheader_materiallike"
android:layout_gravity="bottom"
android:background="#FFF">
<!--<TextView-->
<!--android:id="#+id/text_header"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center_vertical"-->
<!--android:layout_marginLeft="70dp"-->
<!--android:text="ttttt"-->
<!--android:textColor="#android:color/white"-->
<!--android:textSize="18sp"-->
<!--android:textStyle="bold" />-->
<RelativeLayout
android:id="#+id/button_header"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="83dp"
android:layout_marginRight="83dp">
<RelativeLayout
android:id="#+id/photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="2.5">
<ImageView
android:layout_width="17dp"
android:layout_height="14dp"
android:layout_centerInParent="true"
android:background="#drawable/photo_blue_icon"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5">
<ImageView
android:layout_width="14dp"
android:layout_height="16dp"
android:layout_centerInParent="true"
android:background="#drawable/video_blue_icon" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/share"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5">
<ImageView
android:layout_width="15dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:background="#drawable/share_blue_icon" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/fav"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5">
<ImageView
android:layout_width="20dp"
android:layout_height="19dp"
android:layout_centerInParent="true"
android:background="#drawable/fav_blue_icon" />
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_alignParentBottom="true"
android:background="#d7d7d7" />
</RelativeLayout>
</FrameLayout>
</FrameLayout>
</FrameLayout>
and in the java code you should add this
StikkyHeaderBuilder.ListViewBuilder.stickTo(mListView)
.setHeader(R.id.header, (ViewGroup) contentView)
.minHeightHeaderDim(R.dimen.min_height_textheader_materiallike)
.animator(new ParallaxStikkyAnimator())
.attatch_Acitivty(Attractions.this)
.castTo("Attractions")
.build();
and here is the library used
but i have modified this library to work as i want
the modification is add method in stcikylistview builder to know the activity used and pass a delegate for scrolling i used this because i added a blur for images in the viewpager
and her is my modification
i will upload the modified version of the library
here you are https://drive.google.com/file/d/0BxdN8PyW5nmHMmFFeFY2aW9zdlk/view?usp=sharing
I had this issue as well. You'll need to used RecyclerView. Now I understand you must use ListView and GridGiew, but you can use that within a RecyclerView.
For example, I'll show you how to implement a GridLayout within in a RecyclerView.
In your fragment layout (that you'd want to implement GridView in), add the following XML
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/recyclerviewGRID"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Then on your fragment java,
on your fragment onCreateView, define the RecyclerView,
RecyclerView rv = (RecyclerView) v.findViewById(R.id.recyclerviewGRID);
setupRecyclerView(rv);
Create the method setupRecyclerView,
private void setupRecyclerView(RecyclerView recyclerView) {
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(recyclerView.getContext(), 2));
mAdapter = new AdapterGridView(getActivity().getApplicationContext(), mItems);
recyclerView.setAdapter(mAdapter);
}
You must define mAdapter as RecyclerView.Adapter first. Then create your the adapter for the RecyclerView. Note that, mItems is an ArrayList that will contain contents of your list.
AdapterGridView.java
public class AdapterGridView extends RecyclerView.Adapter<AdapterGridView.ViewHolder> {
ArrayList<AdItem> mItems;
Context context, contxt;
public AdapterGridView(Context context, ArrayList<AdItem> mItems) {
this.context = context;
this.mItems = mItems;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
//attach your list item layout here, mine in this case is called list_item_grid_item
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.list_item_grid_item, viewGroup, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
#Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
AdItem singleItem = mItems.get(i);
//attach data to your layout as the following manner
viewHolder.tvspecies.setText(singleItem.getName());
}
#Override
public int getItemCount() {
//return the number of list items
return mItems.size();
}
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public ImageView imgThumbnail, avatar;
public TextView tvspecies, adIDLBL;
public ViewHolder(View itemView) {
super(itemView);
itemView.setClickable(true);
itemView.setOnClickListener(this);
//define your list item views, basically the stuff in list_item_grid_item
imgThumbnail = (ImageView)itemView.findViewById(R.id.img_thumbnail);
tvspecies = (TextView)itemView.findViewById(R.id.tv_species);
}
#Override
public void onClick(View v) {
//handle item click events
}
}
}

Two RecyclerViews under each other in one layout

How can I get two RecyclerViews under each other in one layout? I don't want to have a single RecyclerView for all items.
My code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#color/main__item_background"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:text="#string/find_friends__already_playing"
android:background="#color/header"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="#dimen/list_header"
android:visibility="visible"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/in_app_friends"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView
android:text="#string/find_friends__invite_friends"
android:background="#color/find_friends__header"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="#dimen/list_header" />
<android.support.v7.widget.RecyclerView
android:id="#+id/friends_to_invite"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
I've found the answer myself.
You need to put the LinearLayout into a ScrollView and use wrap_content as RecyclerView's layout_height.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="#dimen/list_header"
android:background="#color/header"
android:gravity="center"
android:text="#string/find_friends__already_playing"
android:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/in_app_friends"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="#color/white"/>
<TextView
android:layout_width="match_parent"
android:layout_height="#dimen/list_header"
android:background="#color/find_friends__header"
android:gravity="center"
android:text="#string/find_friends__invite_friends" />
<android.support.v7.widget.RecyclerView
android:id="#+id/friends_to_invite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"/>
</LinearLayout>
</ScrollView>
Also there is a bug with with RecyclerView and wrap_content so you have to use a custom layout manager. Check out this post: How do I make WRAP_CONTENT work on a RecyclerView
You should create an XML layout file like this
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/ingredients_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/steps_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
And in the code, you should call setNestedScrollingEnabled(false)
RecyclerView ingredientsList = findViewById(R.id.ingredients_list);
RecyclerView stepsList = findViewById(R.id.steps_list);
ingredientsList.setNestedScrollingEnabled(false);
stepsList.setNestedScrollingEnabled(false);
I also had the same problem and wrote a library which helps to achieve this by joining adapters and layouts.
Gradle dependency to try it (needs jcenter repo):
compile 'su.j2e:rv-joiner:1.0.3'//latest version by now
Thea change xml to use a single RecyclerView which matches parent:
<android.support.v7.widget.RecyclerView
android:id="#+id/joined_friends_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:background="#color/white"/>
Then init RecyclerView in code like this:
//init your RecyclerView as usual
RecyclerView rv = (RecyclerView) findViewById(R.id.joined_friends_rv);
rv.setLayoutManager(new LinearLayoutManager(this));
//construct a joiner
RvJoiner rvJoiner = new RvJoiner();
rvJoiner.add(new JoinableLayout(R.layout.your_title_for_in_app));
rvJoiner.add(new JoinableAdapter(new YourInAppRvAdapter()));
rvJoiner.add(new JoinableLayout(R.layout.your_title_for_invite));
rvJoiner.add(new JoinableAdapter(new YourInviteRvAdapter()));
//set join adapter to your RecyclerView
rv.setAdapter(rvJoiner.getAdapter());
You can check this link for more library details and explanation. Hope it helps.
if you get the bottom recyclerview not scrolling with the main content, change the LinearLayout (see answer from alan_derua) to ConstraintLayout and wrap the two RecyclerViews inside. See code below:
<ScrollView 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="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:id="#+id/task_list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/first_list_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:gravity="left"
android:paddingTop="0dp"
android:text="#string/my_tasks"
app:layout_constraintBottom_toTopOf="#+id/second_list_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/first_list_view" />
<android.support.v7.widget.RecyclerView
android:id="#+id/second_list_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
This worked for me!
You can give each RecycleView height equal to 0dp and weight equal 1:
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
Use NestedScrollView as parent layout, it should have
android:weightSum="2"
and give
android:layout_weight="1"
to each RecyclerView of yours.It should be scrolled one after each other.
Just use:
<android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:scrollbars="vertical"
android:layout_below="#+id/your_first_recycler"/>
last line is for your problem.use it.

Categories

Resources