4
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.tech.world.MainActivity"
    tools:showIn="@layout/app_bar_main_activity"
    android:fillViewport="true" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin" >

        <TextView
            android:id="@+id/textView"
            android:textColor="#43a047"
            android:typeface="serif"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="@string/app"
            android:gravity="center"
            android:textStyle="bold"
            android:textSize="15sp" />


        <android.support.v7.widget.RecyclerView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/recyclerview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView"
            android:layout_marginTop="10dp"
            android:divider="@color/colorAccent"
            android:dividerHeight="1dp" />

</RelativeLayout> </android.support.v4.widget.NestedScrollView>

now the textview above dont show up,i have to scroll a bit down to see the textview,also i am using toolbar which expands and contacts in coordinator layout due to this app:layout_behavior="@string/appbar_scrolling_view_behavior"

i want to make sure textview is visible on start without scrolling a bit to see it

3 Answers3

5

Set android:focusableInTouchMode="true" to your recycler view's parent layout i.e your relative layout.

Check this post.

Community
  • 1
  • 1
Akash Patel
  • 2,757
  • 1
  • 22
  • 30
0

Switching to ConstraintLayout was my solution

Jeffrey
  • 1,998
  • 1
  • 25
  • 22
0

My Working Code using CoordinatorLayout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".PostsActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/MyMaterialTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/MyMaterialTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:id="@+id/txtUserName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="User"
            android:textAlignment="center"
            android:textSize="25sp"
            android:textStyle="bold"
            android:layout_marginBottom="@dimen/padding_10"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:orientation="vertical"
            android:scrollbars="vertical"
            android:layout_below="@+id/txtUserName"/>

    </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>
bmacharia
  • 1,026
  • 10
  • 12