当我在内部使用标签布局和回收者视图时,我看到了一个片段,问题是回收者视图根本没有滚动,任何想法为什么?
<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>
当我向Recycler视图添加填充时,它可以正常工作,但它从标签布局中占用了一个空间
答案 0 :(得分:2)
将此attr添加到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>
答案 1 :(得分:1)
您可以尝试在{{ flash.error|escape('js') }}
RecyclerView
吗?
NestedScrollView
答案 2 :(得分:0)
鉴于必须在CoordinatorLayout
内滚动,您必须编写此参数:
app:layout_behavior=""@string/appbar_scrolling_view_behavior""
答案 3 :(得分:0)
将以下行添加到您的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>