【发布时间】:2016-04-08 14:16:28
【问题描述】:
所以我一直面临RecyclerView滚动这个奇怪的问题。
我先说一下我的要求:
- 我需要在
ToolBar上方有一个菜单。有点像滑动 单击按钮时从顶部打开的抽屉布局。一世 通过创建自定义滑动抽屉来实现这一点。这个抽屉 可见性在开始时设置为 GONE。当用户点击 菜单图标,可见性设置为 VISIBILE。 -
CoordinatorLayout和ToolBar,其中包括一个菜单按钮。 -
ToolBar下方的视差图像在滚动时会缩小。 - 一个
SwipeToRefreshLayout,里面有RecyclerView。
我面临两个问题:
-
RecyclerView滚动一点也不流畅。当我滚动到 底部,列表项仅在一秒钟后可见。它卡住了 第一次滚动时介于两者之间。我确定一定有 平滑滚动的操作。 - 当我单击菜单图标时,菜单布局可见。一旦是
再次隐藏,
RecyclerView的一部分完全消失了。不确定 为什么。请在下面找到有关此问题的屏幕截图
看截图
[![在此处输入图片描述][1]][1]
- 第一张截图是正常的样子
- 第二张截图是菜单布局
- 第三张截图是菜单关闭后的画面
我对如何解决这个问题完全无能为力,因此感谢您提供任何帮助。
我的布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.app.ranky.menu.Transparent
android:id="@+id/popup_window"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left">
<LinearLayout
android:background="#320d77"
android:id="@+id/content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_marginTop="@dimen/margin_large"
android:id="@+id/menu_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TableLayout
android:layout_marginTop="-10dp"
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginRight="@dimen/margin_large"
android:layout_marginBottom="@dimen/margin"
android:layout_width="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_height="wrap_content">
<TableRow
android:layout_marginRight="@dimen/margin"
android:layout_marginLeft="@dimen/margin"
android:layout_marginBottom="@dimen/margin"
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView android:src="@drawable/ic_whatsapp"
android:id="@+id/id_whatsapp"
android:layout_weight="1"
android:padding="@dimen/padding_small"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView android:src="@drawable/ic_fb"
android:id="@+id/id_fb"
android:layout_weight="1"
android:padding="@dimen/padding_small"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView android:src="@drawable/ic_mail"
android:id="@+id/id_mail"
android:layout_weight="1"
android:padding="@dimen/padding_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
</TableRow>
</TableLayout>
</LinearLayout>
</com.app.ranky.menu.Transparent>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="183dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_home_banner"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<ImageButton
android:src="@drawable/ic_slidemenu"
android:background="@null"
android:id="@+id/slide_menu_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.app.ranky.views.CustomTextView
android:paddingRight="45dp"
android:text="@string/app_name"
android:id="@+id/app_title"
android:layout_centerInParent="true"
android:textSize="18dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#cfccd8"
app:font="circular_book" />
<RelativeLayout
android:layout_gravity="right"
android:gravity="right"
android:paddingTop="@dimen/padding"
android:paddingBottom="@dimen/padding"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/padding_large"
android:paddingRight="@dimen/padding_large"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:layout_alignParentRight="true"
android:src="@drawable/ic_plus_small"
android:background="@drawable/add_app_circle"
android:id="@+id/app_add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<com.app.ranky.views.CustomSwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_overlapTop="30dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listOfferItems"
android:listSelector="#00000000"
android:fadingEdge="none" android:fadingEdgeLength="0dp"
android:cacheColorHint="@android:color/transparent"/>
</com.app.ranky.views.CustomSwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
透明类基本上就是一个linearLayout类:
public class Transparent extends LinearLayout {
public Transparent(Context context, AttributeSet as) {
super(context, as);
}
public Transparent(Context context) {
super(context);
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
}
}
【问题讨论】:
-
好的。这个怎么样?我可以将 CoordinatorLayout 添加为 LinearLayout 的子项吗?似乎没有人这样做,我认为这个问题是因为它是 LinearLayout 的孩子之一(另一个是滑动抽屉)
-
所以我通过使用 LinearLayoutManager 的自定义实现并覆盖 smoothScrollToPosition 解决了滚动问题。仍在努力解决第二个问题。非常感谢您在正确方向上的任何帮助
标签: android android-recyclerview slidingmenu android-coordinatorlayout slidingdrawer