Textview不会出现在nestedscrollview android中的RecyclerView上面

时间:2016-10-28 13:05:54

标签: android

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

现在上面的textview没有显示,我必须向下滚动才能看到textview,我也在使用工具栏,它会在协调器布局中展开和联系 应用程式:layout_behavior = “@串/ appbar_scrolling_view_behavior”

我想确保textview在启动时可见而不需要滚动一下才能看到它

3 个答案:

答案 0 :(得分:4)

android:focusableInTouchMode="true"设置为您的回收站视图的父布局,即您的相对布局。

选中post

答案 1 :(得分:0)

切换到ConstraintLayout是我的解决方案

答案 2 :(得分:0)

我使用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>