I'm not having any luck with hiding my app bar when a RecyclerView within a ViewPager is scrolled. I found the post:
CoordinatorLayout using the ViewPager's RecyclerView
But am not having any luck with it. Here is my activities layout file:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
app:layout_scrollFlags="scroll|enterAlways|snap">
</include>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<include
android:id="#+id/drawer_list"
layout="#layout/nav_drawer_list_view" />
<include
android:id="#+id/citizensFilter"
layout="#layout/citizens_activity_filter" />
</android.support.v4.widget.DrawerLayout>
The fragment has a good amount of views inside, so I'm not sure if that could be an issue:
<?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:animateLayoutChanges="true"
android:background="#color/colorCitizenBackground" >
<TextView
android:id="#+id/tvUpgrade"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true"
android:gravity="center"
android:text="#string/load_more_profiles"
android:textSize="16sp"
android:textColor="#color/white" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/layoutSwipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tvUpgrade"
android:layout_below="#+id/horizontalScrollView1" >
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerCitizens"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/citizen_filter_color"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollbars="none" >
<TextView
android:id="#+id/tvFilterList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</HorizontalScrollView>
<include android:id="#+id/layoutNoneFound"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/view_no_search_results"
android:layout_below="#+id/horizontalScrollView1" />
<include android:id="#+id/layoutLoading"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/view_loading"
android:layout_below="#+id/horizontalScrollView1" />
<include android:id="#+id/layoutGetLocation"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/view_determine_location"
android:layout_below="#+id/horizontalScrollView1" />
<RelativeLayout
android:id="#+id/layoutDiscover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:clickable="true"
android:visibility="invisible" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/rounded_corners_discover"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingRight="20dp"
android:paddingEnd="20dp">
<TextView
android:id="#+id/tvDiscover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/discover"
android:textColor="#color/colorPrimaryText"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="#+id/spDiscover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|end"
android:layout_weight="1" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerDiscover"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
I have even attempted to set the CoordinatorLayout programmatically using;
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.setBehavior(new AppBarLayout.ScrollingViewBehavior());
recyclerCitizens.setLayoutParams(params);
But that still didn't have an effect. What am I missing? I was under the impression setting the layout_behavior on the ViewPager would allow this implementation.
I was able to figure out what the problem was. In my layout file, I could not do an <include> statement. I had to change:
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
app:layout_scrollFlags="scroll|enterAlways|snap">
</include>
to:
<android.support.v7.widget.Toolbar
android:id="#+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap"/>
Related
I am trying to use CoordinatorLayout and CollapsingToolbar and SoftInputMode.When I tried to use android:fitsSystemWindows="false" in Coordinator Layout. It works well. But, SoftInputMode not working. That means when EditText is active the layout must resize. I added SOftInputMode to Manifest file.But ,It is not working.
The problem is when android:fitsSystemWindows="false", status bar background not working. But, Layout resizing working well.
Similarly, when android:fitsSystemWindows="true", status bar background works well. But, Layout resizing not working.
My code for Layout is
<?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"
app:statusBarBackground="#color/myCustomColor"
android:theme="#style/AppThemeCorrdinate"
android:fitsSystemWindows="false"
tools:context="com.uiresource.messenger.Conversation">
<android.support.design.widget.AppBarLayout
android:id="#+id/htab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/my_gradient_bg"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay"
app:expanded="false">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsetoolbar"
android:layout_width="match_parent"
android:layout_height="330dp"
android:fitsSystemWindows="true"
app:contentScrim="#drawable/my_gradient_bg"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="#+id/realTabContent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>
<TabWidget
android:id="#android:id/tabs"
style="#style/MyTabStyle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="bottom"
android:layout_weight="0"
android:orientation="horizontal"
android:showDividers="none"
android:visibility="gone" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
<HorizontalScrollView
android:id="#+id/chipscrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:fitsSystemWindows="true"
android:scrollbars="none">
<RadioGroup
android:id="#+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:scrollbars="none">
</RadioGroup>
</HorizontalScrollView>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:background="#android:color/black"
android:fitsSystemWindows="true"
app:layout_collapseParallaxMultiplier="1.0" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
android:layout_marginBottom="0dp"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/user1" />
<TextView
android:id="#+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center"
android:textAllCaps="false"
android:textAppearance="#style/Light"
android:textColor="#android:color/white"
android:textSize="#dimen/h1" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/htab_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="gone"
app:tabIndicatorColor="#android:color/white"
app:tabSelectedTextColor="#android:color/white"
app:tabTextColor="#color/white" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/add_to_cart_fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#android:drawable/ic_menu_save"
android:visibility="gone"
app:layout_anchor="#id/toolbar"
app:layout_anchorGravity="bottom|right" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/add_to_cart_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="#android:drawable/ic_menu_save"
android:visibility="gone"
app:layout_anchor="#id/htab_appbar"
app:layout_anchorGravity="bottom|center" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/root_layout"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fillViewport="true"
>
<RelativeLayout
android:id="#+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/rl_bottom">
<LinearLayout
android:id="#+id/layout_rvh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/chaty_bg"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingTop="8dp"
android:paddingBottom="20dp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<HorizontalScrollView
android:id="#+id/hsv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#color/white"
android:gravity="bottom"
android:scrollbars="none"
android:visibility="visible">
<LinearLayout
android:id="#+id/chat_quick_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<include
layout="#layout/rich_replies_card"
android:visibility="visible" />
</LinearLayout>
</HorizontalScrollView>
<RelativeLayout
android:id="#+id/editContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/hsv_content"
android:background="#E9EDED"
android:paddingLeft="#dimen/space10"
android:paddingTop="#dimen/space5"
android:paddingRight="#dimen/space5"
android:paddingBottom="#dimen/space5">
<ImageButton
android:id="#+id/bt_send"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:background="#drawable/bg_btnsend_rounded"
android:gravity="center"
android:padding="#dimen/space5"
android:src="#drawable/baseline_send_white_36"
android:stateListAnimator="#null"
android:textAppearance="#style/Light"
android:textColor="#color/white"
android:textSize="#dimen/h3" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/space5"
android:layout_toLeftOf="#id/bt_send"
android:background="#drawable/bg_white_rounded">
<ImageButton
android:id="#+id/bt_attachment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:padding="#dimen/space10"
app:srcCompat="#drawable/ic_attachment" />
<EditText
android:id="#+id/et_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/bt_attachment"
android:background="#android:color/transparent"
android:hint="Enter your message"
android:inputType="textCapSentences"
android:maxLines="3"
android:padding="#dimen/space10"
android:textAppearance="#style/ThemeOverlay.AppCompat.Dark"
android:textColor="#color/colorTextBlack"
android:textColorHint="#color/colorTextHint"
android:textSize="#dimen/h2" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
android:gravity="bottom">
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
1.remove android:fitsSystemWindows="false",Because it can lead to layout scroll.on the Android 4.x
2.By setting style them to change the statusbar color.
How to place Tablayout below the toolbar? It is giving me an error message and when i run it the toolbar doesn't show. But when i give the Tablayout alignbottom the toolbar then shows
Here is my xml file
<RelativeLayout 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:id="#+id/rel"
tools:context="com.example.test.MainActivity">
<include
android:id="#+id/app_bar"
layout="#layout/toolbar"/>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nvd_act_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/app_bar"
>
<FrameLayout
android:id="#+id/cont_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/lbl_act_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello World!" />
</FrameLayout>
<android.support.v7.widget.RecyclerView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/lst_nav_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start|left"
android:background="#android:color/white"
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
</android.support.v4.widget.DrawerLayout>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="#2480c1"
android:gravity="center"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="#+id/tbl_basic"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</android.support.design.widget.TabLayout>
<TextView
android:id="#+id/lbl_basic_content"
android:layout_below="#id/tbl_basic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:textColor="#android:color/black" />
</RelativeLayout>
</RelativeLayout>
Here is the screen i created, the tablayout is in the bottom. I want it to be just below the toolbar. How do i do it? Thanks
Here is the error message
#id/rel is not a sibling in the same RelativeLayout
Layout constraints in a given RelativeLayout should reference other views within the same relative layout (but not itself!)
try this
change
android:layout_alignParentBottom="true" to android:layout_alignParentBottom="false"
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="false"
android:layout_below="#+id/app_bar "
android:background="#2480c1"
android:gravity="center"
android:layout_gravity="center">
<android.support.design.widget.TabLayout
android:id="#+id/tbl_basic"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</android.support.design.widget.TabLayout>
<TextView
android:id="#+id/lbl_basic_content"
android:layout_below="#id/tbl_basic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:textColor="#android:color/black" />
</RelativeLayout>
If you want it below the toolbar, then put it below the toolbar:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/app_bar"
layout="#layout/toolbar" />
<RelativeLayout
android:layout_below="#id/app_bar"
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="#2480c1"
android:gravity="center">
<android.support.design.widget.TabLayout
android:id="#+id/tbl_basic"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>
<TextView
android:id="#+id/lbl_basic_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tbl_basic"
android:gravity="top"
android:textColor="#android:color/black" />
</RelativeLayout>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/nvd_act_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/app_bar"
>
<FrameLayout
android:id="#+id/cont_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/lbl_act_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello World!" />
</FrameLayout>
<android.support.v7.widget.RecyclerView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/lst_nav_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start|left"
android:background="#android:color/white"
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
I have a static image on appbar and below that I am using scrollView which contain my edit text.So the problem is that when I focus on edit text soft keyboard hide my fields.It can't push the app bar image up.I try using android:windowSoftInputMode="adjustPan|adjustUnspecified" all these combination but it didn't work .Can any one suggest better way out.
my root view
<?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/activity_register_simplify"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="org.tta.mobile.view.Register_simplify">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:fitsSystemWindows="false"
app:expanded="false">
<LinearLayout
android:layout_width="413dp"
android:layout_height="145dp"
android:background="#drawable/mx_header_banner">
</LinearLayout>
<!--Tab layout-->
<LinearLayout
android:layout_height="64dp"
android:id="#+id/register_simplified_tablayout_ll_id"
android:visibility="visible"
android:orientation="vertical"
android:layout_width="match_parent">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
app:tabMode="fixed"
app:tabGravity="fill"
android:layout_height="#dimen/mx_signup_signin_top_tablayout_height"
style="#style/MyCustomTabLayout"
app:tabTextColor="#color/black"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:tabIndicatorColor="#22d2c5"
android:id="#+id/mRegisteractivityTabs">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="SIGN-IN"
/>
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="REGISTER"
/>
</android.support.design.widget.TabLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
and my view inside pageviewer which contain fields
<RelativeLayout 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:id="#+id/mx_sign_up_fragment"
android:orientation="vertical"
android:background="#android:color/white"
tools:context="org.tta.mobile.mx_views.SignUpFragment">
<!--android:paddingTop="#dimen/mx_scroll_view_top_padding"-->
<ScrollView
android:id="#+id/scrollview_register"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="50dp"
android:background="#android:color/white"
android:layout_centerVertical="true"
android:layout_alignParentStart="true">
<LinearLayout
android:id="#+id/registrationLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/manprax_sign_in_Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<LinearLayout
android:id="#+id/message_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<include layout="#layout/panel_message_with_check" />
</LinearLayout>
<LinearLayout
android:id="#+id/required_fields_layout_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/mx_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
android:layout_alignParentBottom="true">
<!-- <FrameLayout
android:layout_height="40dp"
android:layout_width="match_parent"
android:focusable="true"
android:id="#+id/mx_signup_remember_me_layout" >
<CheckBox
android:layout_width="match_parent"
android:id="#+id/mx_signup_remember_me_Chkbx"
android:text="Remember me"
android:layout_height="40dp" />
</FrameLayout>-->
<FrameLayout
style="#style/edX.Widget.Sign_In_Manprax_Layout"
android:layout_height="#dimen/mx_btn_height"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:focusable="true"
android:id="#+id/send_OTP_button_layout"
android:contentDescription="#string/create_account_btn">
<TextView
style="#style/edX.Widget.SignInButton"
android:id="#+id/send_OTP_tv"
android:text="#string/send_OTP_text" />
<include layout="#layout/button_progress_indicator" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>
I have this layout:
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<--There is some layouts here-->
<RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
It works well. I can scroll RecyclerView smoothly without scrolling parent view.
Now I have to put the RecyclerView inside a FrameLayout like this:
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<--There is some layouts here-->
<FrameLayout
android:id="#+id/review_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="#+id/empty_view"
layout="#layout/review_empty_view"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Now I cannot scroll the RecyclerView smoothly.
All I want is: scroll RecyclerView smoothly without scrolling parent view. What should I do?
EDIT: Here is my review_empty layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/shopping_review_empty" />
<android.support.v4.widget.Space
android:layout_width="32dp"
android:layout_height="0dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shopping_no_review_message" />
</LinearLayout>
just enable nestedscrolling that will enable smooth scrollview.
RecyclerView v = (RecyclerView) findViewById(...);
v.setNestedScrollingEnabled(false);
Use this in your recyclerView
app:layout_behavior="#string/appbar_scrolling_view_behavior"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#+id/review_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
<include
android:id="#+id/empty_view"
layout="#layout/review_empty_view"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
Try this...
I am suggesting you to do like this. When you get Empty Data then just set Recycler View Visibility as Gone and set Empty View Visibility as Visible.
Here is Code :
<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:background="#color/white"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#color/bg"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
app:layout_collapseMode="parallax">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_30dp">
<include layout="#layout/image_loading_progress" />
<com.thenakedconvos.stories.utils.CircularImageView
android:id="#+id/ivProfile"
android:layout_width="#dimen/scale_90dp"
android:layout_height="#dimen/scale_90dp"
android:transitionName="#string/transition_image" />
</FrameLayout>
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_15dp"
android:textColor="#color/black"
android:textSize="16sp"
android:transitionName="#string/transition_text"
app:typeface="gotham_medium" />
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvHoots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_5dp"
android:textColor="#color/text_color"
android:textSize="12sp"
app:typeface="gotham_book" />
<com.vanniktech.emoji.EmojiTextView
android:id="#+id/tvSmiley"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_10dp"
android:textIsSelectable="true"
app:emojiSize="25sp" />
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvAddFriend"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_15dp"
android:background="#drawable/red_rect_box"
android:gravity="center"
android:paddingBottom="#dimen/scale_12dp"
android:paddingTop="#dimen/scale_12dp"
android:text="Add"
android:textColor="#color/red"
android:textSize="14sp" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:theme="#style/AppTheme">
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/text_color"
android:textSize="18sp"
app:typeface="bariol_bold" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/scale_15dp"
android:background="#color/white"
android:orientation="vertical"
android:padding="#dimen/scale_16dp">
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvUserStory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amy N. Johnson's Stories"
android:textColor="#color/black"
android:textSize="15sp"
app:typeface="bariol_bold" />
<com.thenakedconvos.stories.widget.CustomTextView
android:id="#+id/tvTotalStories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_5dp"
android:text="110 Stories"
android:textColor="#color/text_color"
android:textSize="13sp"
app:typeface="bariol_bold" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/scale_10dp"
android:clipToPadding="false"
android:paddingTop="#dimen/scale_10dp" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
That may be a chance you loading images(static) in to ImageView can be slow your recyclerView.
Or Big size of image.
Try to run application on mobile have good size of RAM
Add fillViewport is true in NestedScrollView in xml file as below:
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
And In your activity setNested scrolling false as below code
recycler_view.setNestedScrollingEnabled(false);
Just put your "not scrollable" layout outside the nested scroll view
All you have to do is use below line in your activity class:
ViewCompat.setNestedScrollingEnabled(recycler_view, false);
its compatible for lower versions also. and if you want to give compatible to API >21 only then use;
recycler_view.setNestedScrollingEnabled(false);
My issue is the editText on the tabLayout is child fragment , when i input edittext the actionbar will up and disappear.
I try to add the android:windowSoftInputMode="adjustPan" or add ScrollView on the fragment xml, they are no working.
I can't find the same issue on internet.
Is anyone can teach me the solution,please.
Parent page:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF">
<!--my actionbar is overhere-->
<android.support.v7.widget.Toolbar
android:id="#+id/id_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/ToolBarStyle"
app:layout_scrollFlags="scroll|enterAlways"
android:background="#FF6699">
<TextView
android:id="#+id/textTitle"
android:textSize="18dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/background_light" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<!--Parent Fragment change from here-->
<FrameLayout
android:id="#+id/mainFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_menu"
app:itemIconTint="#color/colorPrimary"/>
</android.support.v4.widget.DrawerLayout>
Child page:
<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:background="#android:color/darker_gray"
android:orientation="vertical"
tools:context=".SubpagesLayout.Homepage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="#android:color/white"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="80sp"
android:id="#+id/genderIcon"
android:layout_gravity="center"
android:layout_weight="1"
app:srcCompat="#drawable/photo_default_female" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/background_light">
<TextView
android:text="Name"
android:textColor="#android:color/black"
android:textSize="30dp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginLeft="125dp"
android:id="#+id/textNameAges"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="543"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:background="#android:color/background_light"
android:layout_width="match_parent"
android:layout_height="10dp"></LinearLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<!--Child fragment change by the TabLayouts-->
<!--body_weight_fragment is one of the tabs-->
<android.support.design.widget.TabLayout
android:id="#+id/tabLayoutHomePage"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
app:tabTextColor="#android:color/white">
</android.support.design.widget.TabLayout>
<view
android:id="#+id/viewPager"
class="android.support.v4.view.ViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</android.support.design.widget.AppBarLayout>
</LinearLayout>
body_weight_fragment:
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">
<!--input editText will let actionbar disappear-->
<EditText
android:id="#+id/editHeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:hint="cm"
android:inputType="number"
android:windowSoftInputMode="adjustPan" />
<Button
android:id="#+id/btnCaculate"
android:layout_width="2dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:background="#drawable/corner_pink"
android:text="caculate"
android:textColor="#android:color/white" />
<EditText
android:id="#+id/editWeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:hint="kg"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="show result"
android:paddingTop="8dp" />
</LinearLayout>
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.github.mikephil.charting.charts.PieChart>
</LinearLayout>
try it in manifest: add (adjustResize + adjustPan) for parent activity
<activity
android:name="main"
android:windowSoftInputMode="adjustPan|adjustResize"/>
I found a solution by myself,i have to use scrollView include the toolaBar.Just like above
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/id_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/ToolBarStyle"
app:layout_scrollFlags="scroll|enterAlways"
android:background="#FF6699">
<TextView
android:id="#+id/textTitle"
android:textSize="18dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/background_light" />
</android.support.v7.widget.Toolbar>
</ScrollView>