I'm working on a view that need to be scrolled using coordinator layout and inside it should have recyclerview.
i've tried several answer, but it didn't work at all.
There's still empty space below the recycler view section.
Here's my activity.xml
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.woi.adeisme.MainActivity"
android:background="#ff0000"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
app:layout_scrollFlags="scroll"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Masa?"
android:paddingTop="60dp"
android:paddingBottom="60dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:background="#0000ff"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_margin = "0dp">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
i've tried :
1. set layout_height = match_parent / wrap content
2. fitsSystemWindow
3. fillPort
and this still not working..
can anybody help me ?
try Linear layout instead of CoordinatorLayout like below this may help
<LinearLayout
android:orientation="vertical"
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:background="#ff0000"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
app:layout_scrollFlags="scroll"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Masa?"
android:paddingTop="60dp"
android:paddingBottom="60dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:background="#0000ff"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:layout_margin = "0dp"/>
<!-- <include layout="#layout/useless_content"/>-->
</LinearLayout>
Related
I'm trying to make my search bar above my tabs but it appears behind it
This my xml file :
<?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"
tools:context="com.cloud.services.drmzr.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cloud.services.drmzr.MainActivity"
android:layout_above="#+id/topBar">
<include layout="#layout/user_search"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/topBar">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabs"
android:background="#drawable/white_grey_border_bottom">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
<RelativeLayout
android:layout_below="#+id/topBar"
android:layout_above="#+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120px"
android:id="#+id/bottomBar"
android:layout_alignParentBottom="true">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/bottomNavView_Bar"
android:background="#drawable/white_grey_border_top"
app:menu="#menu/bottom_navigation_menu">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Honestly, this is not the best layout. Very expensive to measure all relative layouts wrapped to each other. Your elements appear behind each other because you made your view in relative which is very similar to frame layout. I think a better way to do it in ConstraintLayout. But if you want to make it in relative do it like that.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/appBarLayout"
>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabs"
android:background="#drawable/white_grey_border_bottom">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/user_search"
android:id="#+id/user_search"
android:layout_below="#+id/appBarLayout"
android:layout_height="20dp"
android:layout_width="match_parent"
/>
<android.support.v4.view.ViewPager
android:layout_below="#+id/user_search"
android:layout_above="#+id/bottomNavView_Bar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/container"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="120px"
android:id="#+id/bottomNavView_Bar"
android:background="#drawable/white_grey_border_top"
app:menu="#menu/bottom_navigation_menu"
android:layout_alignParentBottom="true">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
place your search layout below tab layout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cloud.services.drmzr.MainActivity"
android:layout_below="#id/tab_layout">
<include layout="#layout/user_search"/>
</RelativeLayout>
check this line : android:layout_below="#id/tab_layout"
I want to set layout_weight with viewpager 40% and recyclerview 60% in below code. But its not showing properly.It not showing properly in 6.0 but works perfectly in above 6.0 versions.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="#+id/rel"
android:orientation="vertical"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_alignParentTop="true" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="-20dp"
android:padding="10dip"
app:centered="true"
app:radius="20dp"
android:layout_alignParentBottom="true"
app:pageColor="#e5e5e5"
app:fillColor="#ffffff"
app:snap="false" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:id="#+id/rcv"
android:layout_weight="2"
></android.support.v7.widget.RecyclerView>
</LinearLayout>
Below is my activity where i am replacing this fragment file.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.laundry.laundryapp.activity.Navigation_drawer">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<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"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.laundry.laundryapp.activity.Navigation_drawer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/lin"
android:layout_alignParentTop="true"
android:layout_above="#+id/navigation">
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
android:layout_alignParentBottom="true"
app:menu="#menu/navigation" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main2"
app:menu="#menu/activity_main2_drawer" />
</android.support.v4.widget.DrawerLayout>
Hey, I read somewhere that it is recommended to assign weight to all
the children of the parent layout. Also, it is important to include
weightSum in the parent view and the height of the views should be 0dp (or width in case the orientation is "horizontal")
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/rel"
android:weightSum="20">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
/>
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_marginTop="-20dp"
android:padding="10dip"
app:centered="true"
app:radius="20dp"
android:layout_alignParentBottom="true"
app:pageColor="#e5e5e5"
app:fillColor="#ffffff"
app:snap="false" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:id="#+id/rcv"
android:layout_weight="14"
/>
</LinearLayout>
Try this code, also try adjusting the weights to get the desired look. Hope this works.
You can set android:layout_weight="0.4" and android:layout_weight="0.6"
Use ConstrainLayout combined with Guidelines (in percentage for sure), it's way more easier to arrive what you are looking for.
Followed this link Overlap scrolling view with AppBarLayout but overlapping doesn't seems to work well.Here i'm attaching my layout files with the output that i got.
activity_main.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="192dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
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"
app:behavior_overlapTop="64dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:elevation="5dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/days_list_5"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
custom_layout.xml
<?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:background="#android:color/white"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cardNews"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#color/colorAccent"
android:layout_margin="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/lblNewsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorAccent"
android:textSize="16dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Please have a look and give me your suggestion where i'm wrong.
By removing android:background="#android:color/white" from my custom layout and changing the CollapsingToolBar as app:layout_scrollFlags="scroll|enterAlwaysCollapsed",I resolved the issue.
CoordinatorLayout adds space between AppBarLayout and RecyclerView. Not sure whether its the Toolbar or AppBarLayout.
Screenshot of the rendered layout on phone:
The design rendering on Studio doesn't how this space.
Any idea on what's going on?
The Code Itself.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_home_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
>
<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_home_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ActivitySignIn">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:theme="#style/OTGToolbarTheme"
>
<TextView
android:id="#+id/toolbar_title"
style="#style/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="You are logged in"
android:textColor="#color/colorAccent"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/activity_home_articlecontainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="0dp"
android:background="#color/colorPrimary"
android:clipToPadding="false"
android:paddingTop="0dp"
app:behavior_overlapTop="?attr/actionBarSize"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/NavigationDrawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/colorPrimary"
android:scrollbars="vertical"
/>
</android.support.v4.widget.DrawerLayout>
<FrameLayout
android:id="#+id/activity_home_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/tlgray0"
android:orientation="vertical"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"/>
</FrameLayout>
</FrameLayout>
Remove below line from your first Recycler View which id is activity_home_articlecontainer
android:layout_gravity="start"
Before you mark it duplicate, let me tell you that I have searched for every answer but all in vain.
I am using Tabs with Actionbar.
I have set android:layout_height="match_parent" of ScrollView as suggested in many solutions.
I also have removed android:layout_gravity="center" from all layouts as suggested by:
Android scrollview hiding top content in layout
I also have set android:fillViewport="true" but no luck.
Any other hack that I am missing?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<CalendarView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/calendarView" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Guest"/>
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</NumberPicker>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_time_slot"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_add_on"/>
<Button
android:id="#+id/btn_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_btn_confirm"/>
</LinearLayout>
</ScrollView>
Here is xml of activity:
<?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"
android:fitsSystemWindows="true"
tools:context="com.squincy.wspace.ui.HomeActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<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_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="#color/app_color_black"
app:tabTextAppearance="#android:style/TextAppearance.Widget.TabWidget"
app:tabIndicatorColor="#color/app_color_black"
app:tabGravity="center"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<!--<android.support.design.widget.FloatingActionButton-->
<!--android:id="#+id/fab"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="end|bottom"-->
<!--android:layout_margin="#dimen/fab_margin"-->
<!--android:src="#android:drawable/ic_dialog_email" />-->
</android.support.design.widget.CoordinatorLayout>
I think you should try NestedScrollView
<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"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
Just replace your ScrollView with this one
I am using it in my app and it works perfectly
Try adding paddingBottom to your LinearLayout inside ScrollView.
If that doesn't work then try adding Space as last child of LinearLayout inside ScrollView like this:
<ScrollView
<LinearLayout
// other views
<Space
android:layout_width="match_parent"
android:layout_height="required_spacing_in_dp" />
</LinearLayout>
</ScrollView