How do i place image in android toolbar? - android

how do I design profile picture like in this image in android? I tried placing it in the toolbar it won't show half below the toolbar.
Here is a look at the code I am trying. I am using a linear layout at top and then again a linear layout for holding logo and text and the image is at the bottom in root linear layout. Despite setting margin-top it still there and not moving to location:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:menu="#menu/action_menu"
android:background="#color/colorPink1"
android:elevation="0dp"
android:layout_margin="0dp"
app:collapseIcon="#drawable/logo_mini"
android:padding="0dp"
android:layout_height="wrap_content" android:minHeight="0dp">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top"
android:orientation="vertical" android:gravity="end" android:dividerPadding="100dp">
<LinearLayout
android:orientation="vertical"
android:id="#+id/main_layout"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:padding="5dp"
android:paddingLeft="50dp"
android:gravity="center">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/center_icon"
android:layout_gravity="center"
android:src="#drawable/logo_mini"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginTop="5dp"
/>
</LinearLayout>
<ImageView
android:layout_marginTop="5dp"
android:id="#+id/bar"
android:src="#drawable/bar"
android:background="#android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="Hi ,"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/emp_name" android:textSize="30sp"/>
<TextView
android:text="Wellcome back,"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/textView5"/>
<TextView android:layout_width="match_parent" android:visibility="gone" android:layout_height="wrap_content"
android:text="here ae you assigned sites"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_gravity="bottom|end"
android:elevation="10dp"
android:src="#drawable/user_photo"
android:layout_alignBottom="#+id/center_icon"
android:layout_width="72dp"
android:layout_height="72dp"
android:gravity='center'
android:layout_marginTop="-50dp"
/>
</android.support.v7.widget.Toolbar>

you should use CoordinatorLayout and layout_anchor ,layout_anchorGravity attributes for the ImageView to locate the image on the edge of the toolbar
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
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="wrap_content"
android:layout_margin="0dp"
android:background="#color/colorAccent"
android:elevation="0dp"
android:minHeight="0dp"
android:padding="0dp"
app:collapseIcon="#drawable/logo_mini">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:dividerPadding="100dp"
android:gravity="end"
android:orientation="vertical">
<LinearLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:paddingLeft="50dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/center_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:src="#drawable/logo_mini" />
</LinearLayout>
<ImageView
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#android:color/white"
android:src="#mipmap/mic" />
<TextView
android:id="#+id/emp_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hi ,"
android:textSize="30sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wellcome back,"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="here ae you assigned sites"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:id="#+id/icon"
android:layout_width="#dimen/dim150"
android:layout_height="#dimen/dim150"
android:layout_below="#+id/home_txt"
android:layout_marginTop="#dimen/dim20"
android:src="#drawable/user_photo"
app:layout_anchor="#id/toolbar"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>

you can change your layout like this,
<?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.support.v7.widget.Toolbar 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="wrap_content"
android:layout_margin="0dp"
android:background="#color/colorAccent"
android:elevation="0dp"
android:minHeight="0dp"
android:padding="0dp"
app:collapseIcon="#drawable/logo_mini">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:dividerPadding="100dp"
android:gravity="end"
android:orientation="vertical">
<LinearLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:paddingLeft="50dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/center_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:src="#drawable/logo_mini" />
</LinearLayout>
<ImageView
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#android:color/white"
android:src="#mipmap/mic" />
<TextView
android:id="#+id/emp_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hi ,"
android:textSize="30sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wellcome back,"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="here ae you assigned sites"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentRight="true"
android:layout_marginTop="80dp"
android:elevation="10dp"
android:gravity='center'
android:src="#drawable/user_photo" />
</RelativeLayout>

Try to use Constraint Layout to make responsive UI
<android.support.constraint.ConstraintLayout 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=".StartActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/colorPrimary">
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="24dp"
android:background="#color/colorAccent"
android:src="#drawable/ic_launcher_foreground"
app:layout_constraintBottom_toBottomOf="#+id/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" /></android.support.constraint.ConstraintLayout>

Related

How to anchor ImageView to layout

I'm trying to anchor ImageView to layout as below
We can anchor FloatingActionButton but how to anchor a Imageview
I'm not using CoordinatorLayout. i'm using LinearLayout
How can i do that
Try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_account_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary" />
<ScrollView
android:id="#+id/scrolView_account"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/linear_account"
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="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cardView_account_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="70dp"
app:cardCornerRadius="5dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear_account_input_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="NILU"
android:textSize="30sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#mipmap/ic_launcher_round"
android:hint="Enter Email" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#mipmap/ic_launcher_round"
android:hint="Enter Paasword" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Login" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="This is demo" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageview_account_profile"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher_round"
app:civ_border_color="#color/colorWhite"
app:civ_border_width="2dp" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>

how to use scrollview in layout with toolbar and bottomnavigationview?

I have a screen in which there is a toolbar, a bottomNavigationView and some data between them including a textView and an imageView. I want to scroll the inner data that is between the toolbar and bottomNavigationView.
I want to scroll the design.xml inside of main.xml. Please suggest a way I can achieve this.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar1"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<include
layout="#layout/design"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#FFFFFF"
app:itemTextColor="#FFFFFF"
app:menu="#menu/bottom_navigation_main" />
design.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="?android:attr/actionBarSize"
tools:context="com.example.chaitanya.pg.Pgdata">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relative">
<Button
android:id="#+id/btt1"
android:background="#drawable/tprevoius"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="100dp" />
<Button
android:background="#drawable/tnext"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignTop="#+id/btt1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/btt2" />
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/viewPager"/>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview1"
android:layout_width="match_parent"
android:layout_height="100dp"
card_view:cardElevation="5dp"
android:layout_below="#id/viewPager"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Facilities"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:id="#+id/facilities"
android:textSize="20dp"
android:gravity="center"
android:layout_below="#+id/viewPager"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:paddingLeft="10dp"
android:textSize="15dp"
android:id="#+id/wifi"
/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="15dp"
android:id="#+id/ac"
/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:foregroundGravity="right"
android:paddingLeft="20dp"
android:id="#+id/food"
android:textStyle="bold"
android:textSize="15dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview12"
android:layout_width="match_parent"
android:layout_height="60dp"
card_view:cardElevation="5dp"
android:layout_below="#id/cardview1"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accomodation"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:textSize="20dp"
android:gravity="center"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="20dp"
android:id="#+id/accomodation"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview123"
android:layout_width="match_parent"
android:layout_height="60dp"
card_view:cardElevation="5dp"
android:layout_below="#id/cardview12"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Price"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:textSize="20dp"
android:gravity="center"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="20dp"
android:id="#+id/pricee"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:id="#+id/name"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:textSize="20dp"
android:layout_marginLeft="10dp"
android:paddingLeft="20dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:id="#+id/addr"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:layout_marginLeft="10dp"
android:textSize="20dp"
/>
</RelativeLayout>
</LinearLayout>
There needs to be only one layout inside ScrollView.
You do not need to put ScrollView inside ScrollView.
You have added the include tag inside the ScrollView and your
design.xml also has ScrollView.
I would not use android:fillViewport tag inside ScrollView, instead
use properties related to relative layout.
Rest of the things don't seem too difficult to figure out.
from design.xml remove parent <ScrollView> because outsie you already define the scrollview so there is no use of scrollview inside the design.xml
design.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">

NestedScrollView is not working with viewpager in android

In my activity I am using Tablayout bellow 300dp from the top is set. in Tablayout I have 3 fragments, the problem is it's showing the fragments but my layout is not scrolling up. I tried Scrollview and NesterScrollview, but none of them worked. please see my xml code below
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
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:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="260dp"
android:background="#fff">
<!-- Cover Image -->
<ImageView
android:id="#+id/bgimage"
android:layout_width="match_parent"
android:layout_height="180dp"
android:scaleType="fitXY"
android:src="#drawable/profilebg" />
<!-- Round image -->
<ImageView
android:id="#+id/shareicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:tint="#color/black"
android:layout_gravity="bottom"
android:padding="5dp"
android:background="#drawable/imageborder"
android:src="#drawable/share"/>
<android.support.v7.widget.CardView
android:layout_width="140dp"
android:layout_height="140dp"
android:elevation="12dp"
android:id="#+id/view2"
app:cardCornerRadius="100dp"
android:layout_centerHorizontal="true"
android:innerRadius="0dp"
android:shape="ring"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:thicknessRatio="1.9">
<ImageView
android:id="#+id/profilepic"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_gravity="center"/>
</android.support.v7.widget.CardView>
<ImageView
android:id="#+id/editic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:tint="#color/black"
android:layout_marginRight="40dp"
android:background="#drawable/imageborder"
android:padding="6dp"
android:src="#drawable/ic_pencil"/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#fff">
<zesteve.com.myapplication.font.RobotoTextView
android:id="#+id/usertitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tom Cruise"
android:textSize="22dp"
android:textColor="#color/black"
android:layout_gravity="center"/>
<zesteve.com.myapplication.font.RobotoTextView
android:id="#+id/userlocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Syracuse, New York"
android:layout_gravity="center"
android:textColor="#color/black"
android:textSize="14dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="#color/material_purple_500"
android:layout_marginTop="25dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp">
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="256"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="16dp" />
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="LIKES"
android:textSize="12sp"/>
</LinearLayout>
<View
android:layout_width="0.1dp"
android:layout_height="50dp"
android:background="#color/material_purple_500"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp"
>
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2,080"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="16dp" />
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="FOLLOWERS"
android:textSize="12sp"/>
</LinearLayout>
<View
android:layout_width="0.1dp"
android:layout_height="50dp"
android:background="#color/material_purple_500"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="144"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="16dp" />
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="FOLLOWING"
android:textSize="12sp"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="#color/material_purple_500" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="40dp"
app:tabGravity="fill"
app:tabMode="fixed"
style="#style/NavigationTab"
android:background="?attr/colorPrimary"/>
<android.support.v4.view.ViewPager
android:id="#+id/ptab_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
I also tried below
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="260dp"
android:background="#fff">
<!-- Cover Image -->
<ImageView
android:id="#+id/bgimage"
android:layout_width="match_parent"
android:layout_height="180dp"
android:scaleType="fitXY"
android:src="#drawable/profilebg" />
<!-- Round image -->
<ImageView
android:id="#+id/shareicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:tint="#color/black"
android:layout_gravity="bottom"
android:padding="5dp"
android:background="#drawable/imageborder"
android:src="#drawable/share"/>
<android.support.v7.widget.CardView
android:layout_width="140dp"
android:layout_height="140dp"
android:elevation="12dp"
android:id="#+id/view2"
app:cardCornerRadius="100dp"
android:layout_centerHorizontal="true"
android:innerRadius="0dp"
android:shape="ring"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:thicknessRatio="1.9">
<ImageView
android:id="#+id/profilepic"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_gravity="center"/>
</android.support.v7.widget.CardView>
<ImageView
android:id="#+id/editic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:tint="#color/black"
android:layout_marginRight="40dp"
android:background="#drawable/imageborder"
android:padding="6dp"
android:src="#drawable/ic_pencil"/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#fff">
<zesteve.com.myapplication.font.RobotoTextView
android:id="#+id/usertitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tom Cruise"
android:textSize="22dp"
android:textColor="#color/black"
android:layout_gravity="center"/>
<zesteve.com.myapplication.font.RobotoTextView
android:id="#+id/userlocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Syracuse, New York"
android:layout_gravity="center"
android:textColor="#color/black"
android:textSize="14dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="#color/material_purple_500"
android:layout_marginTop="25dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp">
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="256"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="16dp" />
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="LIKES"
android:textSize="12sp"/>
</LinearLayout>
<View
android:layout_width="0.1dp"
android:layout_height="50dp"
android:background="#color/material_purple_500"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp"
>
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2,080"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="16dp" />
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="FOLLOWERS"
android:textSize="12sp"/>
</LinearLayout>
<View
android:layout_width="0.1dp"
android:layout_height="50dp"
android:background="#color/material_purple_500"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="144"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="16dp" />
<zesteve.com.myapplication.font.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="FOLLOWING"
android:textSize="12sp"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="#color/material_purple_500" />
<include layout="#layout/profile_tab_layout"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
and included 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"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="40dp"
app:tabGravity="fill"
app:tabMode="fixed"
style="#style/NavigationTab"
android:background="?attr/colorPrimary"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/ptab_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
IMAGE
this result is second approach using include. its showing tab's and fragments also, but if we scroll top rest of the content will show.

Recycleview not scroll in nested scrollview android

<?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?

NestedScrollview won't start from top

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"

Categories

Resources