I found that my last item in RecyclerView can't show when RecyclerView inside GridLayot.
I try to remove GridLayot and just use RecyclerView, and it can show all items, but I can't use these solution because I need to show my AppBarLayout too. So I need to use GridLayot to make AppBarLayout and RecyclerView be a group, and SwipeRefreshLayout can use.
How can I fix that, thank you!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/activity_cost_diamond_history_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorComtGray">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="1"
android:rowCount="2">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_row="0">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/activity_cost_diamond_history_user_cost_diamond_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="#drawable/ic_point" />
<TextView
android:id="#+id/activity_cost_diamond_history_user_cost_diamond_text"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:textColor="#color/colorBlack"
android:textSize="17sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/activity_cost_diamond_history_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</GridLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
Make recyclerview row 1
<androidx.recyclerview.widget.RecyclerView
android:layout_row="1"
android:id="#+id/activity_cost_diamond_history_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
or Use your layout like this
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/activity_cost_diamond_history_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="1"
android:rowCount="1">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_row="0">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/activity_cost_diamond_history_user_cost_diamond_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="#drawable/ic_back" />
<TextView
android:id="#+id/activity_cost_diamond_history_user_cost_diamond_text"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:textColor="#color/background"
android:textSize="17sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</GridLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/activity_cost_diamond_history_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Related
I am using a BottomNavigationBar and LinearLayout as the first layout tab but this unexpected margin at the top is showing i already changed my dimens to 0dp but nothing changes.
This is my Main 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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/controlView"
android:layout_width="match_parent"
android:layout_height="16dp" />
<FrameLayout
android:id="#+id/content_frag"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorPrimaryDark"
app:menu="#menu/navigation" />
</LinearLayout>
Actually there are two layouts having the same margin problem and this is one of them
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/grey_300">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#drawable/gcover"
android:id="#+id/relativeLayout">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profPhoto"
android:clickable="true"
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="20dp"
android:src="#drawable/default_prof"
android:scaleType="centerCrop"
app:civ_border_color="#color/trans"
app:civ_border_width="2dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="vertical">
<android.support.v7.widget.AppCompatButton
android:id="#+id/prof_invite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="2dp"
android:background="#color/green_300"
android:drawableLeft="#drawable/icon1"
android:padding="12dp"
android:text="invite friends" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/prof_conf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="2dp"
android:background="#color/ball_D"
android:drawableLeft="#drawable/icon2"
android:padding="12dp"
android:text="settings" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/prof_out"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="2dp"
android:background="#color/colorPrimaryDark"
android:drawableLeft="#drawable/icon"
android:padding="12dp"
android:text="log out" />
</LinearLayout>
<View
android:id="#+id/controlView"
android:layout_width="match_parent"
android:layout_height="16dp" />
This is your problem.
Remove this and it will be fine.
I have one outer ScrollView in which there is one RecyclerView and three tabs. Every tab has a fragment and that fragment loads in corresponding tab using ViewPager but outer ScrollView does not scroll my layout. I used nested ScrollView but it also does not scroll. Maybe I did something wrong. Does any one have a suggestion? Please share with me.
Here is my xml code structure
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
android:id="#+id/parent_scroll"
android:layout_weight="1"
android:background="#color/business_price_bg"
android:focusableInTouchMode="false">
<RelativeLayout
android:id="#+id/business_detail_main_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/activity_main_search_top_main_ll"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_main_search_top_main_ll_height"
android:background="#color/location_setting_bottom_button_color"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<RelativeLayout
android:id="#+id/business_detail_activity_business_slider_main_rl"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/activity_main_search_top_main_ll">
<android.support.v7.widget.RecyclerView
android:id="#+id/business_detail_activity_slider_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
<TextView
android:id="#+id/business_detail_activity_business_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_slider_main_rl"
android:layout_margin="10dp"
android:text=""
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/business_detail_activity_business_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_title"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text=""
android:textSize="13sp" />
<android.support.design.widget.TabLayout
android:id="#+id/business_detail_activity_tabslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_description"
android:background="#android:color/transparent"
app:tabIndicatorColor="#color/pencilin_orange_color"
app:tabIndicatorHeight="5dp"
app:tabTextAppearance="#style/MyTabLayoutTextAppearance" />
<android.support.v4.view.ViewPager
android:id="#+id/business_detail_activity_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/business_detail_activity_tabslayout"
android:background="#android:color/white" />
</RelativeLayout>
</ScrollView>
You are going against the Android's UI Standards that's why you can never achieve your goals. Try to stick with Android UI Standards and make less complex UI.
I changed my screen Layout Structure and finally ScrollView is working
Here is solution:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:focusableInTouchMode="true">
<LinearLayout
android:id="#+id/business_detail_main_rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="#+id/activity_main_search_top_main_ll"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_main_search_top_main_ll_height"
android:layout_weight="0."
android:background="#color/location_setting_bottom_button_color"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.45"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/business_detail_activity_business_slider_main_rl"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/activity_main_search_top_main_ll">
<android.support.v7.widget.RecyclerView
android:id="#+id/business_detail_activity_slider_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scrollbars="vertical" />
</RelativeLayout>
<TextView
android:id="#+id/business_detail_activity_business_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_slider_main_rl"
android:layout_margin="10dp"
android:text=""
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/business_detail_activity_business_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_title"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text=""
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_services_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_service_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.12"
android:background="#color/location_setting_bottom_button_color" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_about_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_about_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_about_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.13"
android:background="#color/light_gray_section_cell_seperator" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_staff_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_staff_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_staff_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.13"
android:background="#color/light_gray_section_cell_seperator" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="vertical">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/todoDetailsCoordinatorLayout"
android:background="#color/windowBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/todoEditMainLl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/windowBackground"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/todoDetailsAppBar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/todoDetailsToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetStart="10dp"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/todoDetailsBottomLl"
android:layout_below="#+id/todoDetailsAppBar"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="#+id/todoDetailsScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/todoEditTopLl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/windowBackground"
android:orientation="vertical"
android:visibility="visible">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/eight_dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_vertical_margin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/list_item_single_line_height"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="#dimen/avatar_icon_touch_area_size"
android:layout_height="#dimen/avatar_icon_touch_area_size"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/todo_user"
android:visibility="visible" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/list_item_content_left_padding"
android:gravity="center_vertical"
android:orientation="vertical">
<com.strait.solvenow.Utilities.WithoutPrimaryTextView
android:id="#+id/EditTodoTxtAssignToName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="" />
<com.strait.solvenow.Utilities.WithoutSecondaryTextView
android:id="#+id/EditTodoTxtAssignByName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text=""
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/todo_details_height"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="#dimen/avatar_icon_touch_area_size"
android:layout_height="#dimen/avatar_icon_touch_area_size"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:src="#drawable/todo_due_date" />
</LinearLayout>
<com.strait.solvenow.Utilities.WithoutPrimaryTextView
android:id="#+id/EditToDoTxtDueDate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/list_item_content_left_padding"
android:background="#null"
android:gravity="left|center"
android:text="#string/Due_Date" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/todo_details_height"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="#dimen/avatar_icon_touch_area_size"
android:layout_height="#dimen/avatar_icon_touch_area_size"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/todoDetailsImgStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/user_place_holder" />
</LinearLayout>
<com.strait.solvenow.Utilities.WithoutPrimaryTextView
android:id="#+id/EditToDoTxtStatus"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/list_item_content_left_padding"
android:background="#null"
android:gravity="left|center"
android:text="#string/Status" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/todo_details_height"
android:gravity="center|left"
android:orientation="horizontal">
<LinearLayout
android:layout_width="#dimen/avatar_icon_touch_area_size"
android:layout_height="#dimen/avatar_icon_touch_area_size"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/todo_notification" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/list_item_content_left_padding"
android:orientation="horizontal">
<com.strait.solvenow.Utilities.WithoutPrimaryTextView
android:id="#+id/todoDetailsTxtNotify"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="#string/Notifications" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/todoEditTglNotification"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/ten_dp"
android:layout_toRightOf="#+id/todoDetailsTxtNotify"
android:background="#android:color/transparent"
android:button="#null"
android:checked="false"
android:text=""
android:textColor="#color/textColorWithoutPrimary"
android:textOff=""
android:textOn="" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/todo_details_height"
android:orientation="horizontal">
<LinearLayout
android:layout_width="#dimen/avatar_icon_touch_area_size"
android:layout_height="#dimen/avatar_icon_touch_area_size"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/todoEditImgAttachment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/todo_new_attach" />
</LinearLayout>
<com.strait.solvenow.Utilities.WithoutPrimaryTextView
android:id="#+id/chatEditTxtAttachment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/list_item_content_left_padding"
android:gravity="center|left"
android:text="#string/Attachment" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/todo_details_height"
android:layout_marginLeft="#dimen/list_item_content_left_padding"
android:gravity="center|left"
android:orientation="horizontal">
<com.strait.solvenow.Utilities.WithoutPrimaryTextView
android:id="#+id/chatEditTxtReminder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/todoEditImgAttachment"
android:layout_weight="1"
android:gravity="center|left"
android:text="#string/Reminder"
android:visibility="visible" />
<com.strait.solvenow.Utilities.WithoutPrimaryTextView
android:id="#+id/chatEditTxtForward"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_toRightOf="#+id/todoEditImgAttachment"
android:layout_weight="1"
android:gravity="center|left"
android:text="#string/Forward" />
<com.strait.solvenow.Utilities.WithoutPrimaryTextView
android:id="#+id/chatEditTxtRejected"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/todoEditImgAttachment"
android:layout_weight="1"
android:gravity="center|left"
android:text="#string/Reject" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- <android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/todoSwipeRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/chatWindowBottomRl">
-->
<android.support.v7.widget.RecyclerView
android:id="#+id/todoRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/five_dp"
android:paddingLeft="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/ten_dp"
android:visibility="visible"></android.support.v7.widget.RecyclerView>
<!--</android.support.v4.widget.SwipeRefreshLayout>-->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/todoDetailsBottomLl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<include
android:id="#+id/todoChatBottomVerticalLine"
layout="#layout/divider_view_line"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:background="#color/windowBackground"
android:paddingLeft="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_vertical_margin"
android:visibility="visible">
<ImageView
android:id="#+id/todoChatImgAttachment"
android:layout_width="#dimen/avatar_icon_touch_area_size"
android:layout_height="#dimen/avatar_icon_touch_area_size"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="#dimen/icon_padding"
android:src="#drawable/chat_attachment"
android:visibility="visible" />
<com.strait.solvenow.Utilities.WithoutEditTextView
android:id="#+id/todoChatEdtTextMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/five_dp"
android:layout_toLeftOf="#+id/todoChatImgSend"
android:layout_toRightOf="#+id/todoChatImgAttachment"
android:background="#drawable/chat_window_text_msg_bg"
android:hint=""
android:maxLines="4"
android:minHeight="35dp"
android:paddingLeft="#dimen/ten_dp"
android:text=""
android:textSize="16sp"
android:visibility="visible" />
<ImageView
android:id="#+id/todoChatImgSend"
android:layout_width="#dimen/avatar_icon_touch_area_size"
android:layout_height="#dimen/avatar_icon_touch_area_size"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:padding="#dimen/icon_padding"
android:src="#drawable/send"
android:visibility="visible" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
I have using recycle view inside nested Scroll view but Recycle view not scroll down in nested scroll view.recycle view scroll down when keyboard open and new item add in recycle view.here is above my code.
First of all this is bad layout technique you have implement
According to android standard there are no more than two Scrolling views inside one layout
Make a proper layout for same
You should disable scrolling of recyclerview :
recycler.setNestedScrollingEnabled(false);
You should also set height of recyclerview to wrap_content
android:layout_height="wrap_content"
How to put RecyclerView inside NestedScrollView?
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#FFF"
>
<LinearLayout
android:id="#+id/linear_layout_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="24dp"
android:src="#drawable/ic_search"
android:layout_marginTop="12dp"
android:layout_marginLeft="5dp"
android:singleLine="true"
/>
<EditText
android:id="#+id/autocomplete_places"
android:layout_width="0dp"
android:layout_weight="9"
android:layout_height="50dp"
android:drawablePadding="9dp"
android:hint="#string/autocomplete_hint"
android:paddingLeft="5dp"
android:paddingRight="9dp"
android:singleLine="true"
android:background="#android:color/transparent"
android:textColor="#FFF"
android:textColorHint="#color/white"
android:visibility="visible" />
<ImageView
android:id="#+id/cross"
android:singleLine="true"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="24dp"
android:src="#drawable/ic_clear"
android:layout_marginRight="7dp"
android:layout_marginTop="12dp"
android:visibility="gone"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear_layout_id"
android:id="#+id/pick_position_layout_id"
android:padding="4dp"
android:background="#color/window_background"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
android:elevation="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:src="#drawable/ic_gps"
android:tint="#color/common_action_bar_splitter"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Use My Location"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerViewID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/pick_position_layout_id"
android:scrollbars="vertical"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear_layout_id"
android:scrollbars="vertical" />
</RelativeLayout>
Above is my complete xml file.My problem is that when in below Recyclerview I make height wrap_content it scrolls but when made match_parent it does not scroll can you tell me the reason?
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerViewID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/pick_position_layout_id"
android:scrollbars="vertical"/>
But this Recyclerview works with both match_parent and wrap_content.
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear_layout_id"
android:scrollbars="vertical" />
Can you tell me the reason?
Thanks in advance :)
I have a Recyclerview in a NestedScrollview.. everything is working fine except one thig. I have total three view in NestedScrollview First two are LinearLayout then Recyclerview. when i run my app the Activity don't show top two layout it starts from top of the Recyclerview.
How its show my layout:
How its suppose to show:
And i am loading this enite layout under a viewpager and my viewpager is a child of Coordinator Layout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/home_layout_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.daimajia.slider.library.SliderLayout
android:id="#+id/image_slider"
android:layout_width="match_parent"
android:layout_height="#dimen/image_slider_height"
android:layout_marginTop="#dimen/image_slider_top_margin" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/popular_fragment_side_padding"
android:layout_marginRight="#dimen/popular_fragment_side_padding"
android:layout_marginTop="#dimen/popular_fragment_side_padding"
android:orientation="horizontal"
android:weightSum="4">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/free_delivery"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/btnImageViewFreeDelivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/icon_free_delivery" />
<TextView
android:id="#+id/btnTextFreeDelivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnImageViewFreeDelivery"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="#string/free_delivery_txt"
android:textColor="#color/popular_fragment_four_btn_txt"
android:textSize="#dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/flash_deals"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/btnImageViewFlashDeals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/icon_flash_deals" />
<TextView
android:id="#+id/btnTextFlashDeals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnImageViewFlashDeals"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="#string/flash_deals_txt"
android:textColor="#color/popular_fragment_four_btn_txt"
android:textSize="#dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/for_you"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/btnImageViewForYou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/icon_for_you" />
<TextView
android:id="#+id/btnTextForYou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnImageViewForYou"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="#string/for_you_txt"
android:textColor="#color/popular_fragment_four_btn_txt"
android:textSize="#dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/shake_deals"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/btnImageViewShakeDeals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/icon_shake_deals" />
<TextView
android:id="#+id/btnTextShakeDeals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnImageViewShakeDeals"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="#string/shake_deals"
android:textColor="#color/popular_fragment_four_btn_txt"
android:textSize="#dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/popular_fragment_side_padding"
android:layout_marginRight="#dimen/popular_fragment_side_padding"
android:layout_marginTop="18dp"
android:scrollbars="none" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
My ViewPager Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/home_layout_background"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center"
android:background="#drawable/toolbar_background"
app:layout_scrollFlags="scroll|enterAlways">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/title_home"
android:textColor="#color/toolbar_title_txt_color"
android:textSize="#dimen/toolbar_txt_size"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
app:tabMode="scrollable"
app:tabTextColor="#color/tab_bar_txt"
app:tabIndicatorColor="#color/tab_bar_txt_selected"
app:tabSelectedTextColor="#color/tab_bar_txt_selected"
app:tabTextAppearance="#style/TabTextAppeareance"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
I had the same problem, and I fixed it the following way.
Add android:descendantFocusability="blocksDescendants" to the Linear Layout which is the only child of the Nested Scroll View.
This allows the Nested Scroll View to start from the top with minimal change to code.
It is a problem about focus. Try :
findViewById(R.id.recycler_view).setFocusable(false);
findViewById(R.id.temp).requestFocus();
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/home_layout_background">
<LinearLayout
android:id="#+id/temp"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.daimajia.slider.library.SliderLayout
android:id="#+id/image_slider"
android:layout_width="match_parent"
android:layout_height="#dimen/image_slider_height"
android:layout_marginTop="#dimen/image_slider_top_margin" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/popular_fragment_side_padding"
android:layout_marginRight="#dimen/popular_fragment_side_padding"
android:layout_marginTop="#dimen/popular_fragment_side_padding"
android:orientation="horizontal"
android:weightSum="4">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/free_delivery"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/btnImageViewFreeDelivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/icon_free_delivery" />
<TextView
android:id="#+id/btnTextFreeDelivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnImageViewFreeDelivery"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="#string/free_delivery_txt"
android:textColor="#color/popular_fragment_four_btn_txt"
android:textSize="#dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/flash_deals"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/btnImageViewFlashDeals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/icon_flash_deals" />
<TextView
android:id="#+id/btnTextFlashDeals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnImageViewFlashDeals"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="#string/flash_deals_txt"
android:textColor="#color/popular_fragment_four_btn_txt"
android:textSize="#dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/for_you"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/btnImageViewForYou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/icon_for_you" />
<TextView
android:id="#+id/btnTextForYou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnImageViewForYou"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="#string/for_you_txt"
android:textColor="#color/popular_fragment_four_btn_txt"
android:textSize="#dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/shake_deals"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="#color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/btnImageViewShakeDeals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/icon_shake_deals" />
<TextView
android:id="#+id/btnTextShakeDeals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnImageViewShakeDeals"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="#string/shake_deals"
android:textColor="#color/popular_fragment_four_btn_txt"
android:textSize="#dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/popular_fragment_side_padding"
android:layout_marginRight="#dimen/popular_fragment_side_padding"
android:layout_marginTop="18dp"
android:scrollbars="none" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Just add this line to child of NestedScrollView in xml:
android:focusableInTouchMode="true"
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scrool_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:fitsSystemWindows="false"
>
</android.support.v4.widget.NestedScrollView>
NestedScrollView nested_scrool_view;
nested_scrool_view = mView.findViewById(R.id.nested_scrool_view);
nested_scrool_view.smoothScrollTo(0,0); //set it on top
Add this line in NestedScrollView 's child Layout
android:descendantFocusability="afterDescendants"