簡體   English   中英

回收站視圖不滾動

[英]Recycler view not scrolling

當我在內部和回收站視圖中使用選項卡布局時,我有一個片段視圖,問題是回收站視圖根本不滾動,為什么有什么主意?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:elevation="0dp"

    tools:context="com.carmen.carmen.fragment.dashboard">
    <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.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:background="#FFFFFF"
        android:layout_gravity="center_horizontal"
        app:tabSelectedTextColor="#000000"
        app:tabTextColor="#000000"
        app:elevation="0dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/serviceView"
            android:layout_width="match_parent"
            app:layout_anchor="@+id/tab_layout"
        app:layout_anchorGravity="bottom"
        android:layout_gravity="bottom"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"

            />
        <include layout="@layout/active_service_sheet" />


    </android.support.design.widget.CoordinatorLayout>
</FrameLayout>

當我將填充物添加到回收站視圖時,它可以工作,但是它在選項卡布局中占用了空間

您可以嘗試在NestedScrollView粘貼RecyclerView NestedScrollView

<android.support.v4.widget.NestedScrollView
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:layout_gravity="fill_vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.v7.widget.RecyclerView
        android:id="@+id/serviceView"
        android:layout_width="match_parent"
        app:layout_anchor="@+id/tab_layout"
    app:layout_anchorGravity="bottom"
    android:layout_gravity="bottom"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"

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

將此屬性添加到您的CoordinatorLayout

app:layout_behavior="@string/appbar_scrolling_view_behavior"

或做這樣的事情:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:elevation="0dp"

    tools:context="com.carmen.carmen.fragment.dashboard">
    <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.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:background="#FFFFFF"
        android:layout_gravity="center_horizontal"
        app:tabSelectedTextColor="#000000"
        app:tabTextColor="#000000"
        app:elevation="0dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
    <LinearLayout 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:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >


        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical" />

    </LinearLayout>
 <include layout="@layout/active_service_sheet" />


    </android.support.design.widget.CoordinatorLayout>
</FrameLayout>

在必須在CoordinatorLayout滾動的視圖中,您必須編寫以下參數: app:layout_behavior=""@string/appbar_scrolling_view_behavior""

將以下行添加到您的coordinatorlayout

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

或者您創建如下相同的內容。

main_activity.xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
             android:id="@+id/main_layout"
             android:orientation="vertical"
             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=".MainActivity">

    <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    <!-- our toolbar -->
    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="60sp"
        android:background="@color/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_scrollFlags="scroll|enterAlways">

        <TextView
            android:id="@+id/side_toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="20sp"
            android:textStyle="bold" />
    </android.support.v7.widget.Toolbar>

    <!-- our tablayout to display tabs  -->
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</android.support.design.widget.AppBarLayout>

<!-- View pager to swipe views -->
<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

並在片段布局中創建Recyclerview,如下面的代碼

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
          android:id="@+id/main_layout"
          android:orientation="vertical"
          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=".MainActivity">
    <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <!-- our toolbar -->
    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="60sp"
        android:background="@color/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_scrollFlags="scroll|enterAlways">

        <TextView
            android:id="@+id/side_toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="20sp"
            android:textStyle="bold" />
    </android.support.v7.widget.Toolbar>

    <!-- our tablayout to display tabs  -->
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</android.support.design.widget.AppBarLayout>

<!-- View pager to swipe views -->
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>

並創建一個布局以將其附加到recyclerview。 像下面的代碼

    <?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="220dp"
        android:layout_height="150dp"
        android:layout_margin="5dp">
    <ImageView
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/img4"
        android:scaleType="fitXY"
        android:text="Category"
        android:gravity="center"
        tools:ignore="DuplicateIds" />
    <TextView
        android:id="@+id/id"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/transparent_strip"
        android:text="Today's Deals"
        android:paddingTop="12dp"
        android:paddingBottom="12dp"
        android:textSize="18dp"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:layout_centerInParent="true"/>
</RelativeLayout>

暫無
暫無

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

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