簡體   English   中英

Textview不會出現在nestedscrollview android中的RecyclerView上面

[英]Textview doesnot shows up above RecyclerView in nestedscrollview 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 =“@ string / appbar_scrolling_view_behavior”

我想確保textview在啟動時可見,而不需要滾動一下就可以看到它

android:focusableInTouchMode="true"為您的回收站視圖的父布局,即您的相對布局。

查看這篇文章

切換到ConstraintLayout是我的解決方案

我的工作代碼使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM