私はAndroid Appを開発しています。私のアプリでは、CollapsingtoolbarLayoutとRecyclerViewを併用しています。どちらも機能しています。しかし、私はそれらを配置することに問題があります。私が望むのは、RecyclerViewをCollobing Toobarのすぐ下に置いて、RecyclerViewが折りたたまれているときにツールバーと一緒に移動したいということです。しかし、私のコードは期待どおりに機能していません。RecyclerViewをCollapsingToolbarLayoutの下に置き、Androidで折り畳まれたときにツールバーに反応しますか?
これは今起こっていることです。
あなたはリサイクルビューツールバーで覆われた固定位置を有している見ることができるように。折りたたまれたツールバーには反応しません。
これは私のXMLレイアウトです:
活動で<?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=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/dc_rv_destination"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/htab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/htab_collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/main_activity_parallax_initial_height"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/htab_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/apple"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<TextView
android:layout_centerInParent="true"
android:text="HELLO"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/main_activity_toolbar_height"
android:gravity="top"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleMarginTop="13dp" />
<!-- <android.support.design.widget.TabLayout
android:id="@+id/htab_tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:tabIndicatorColor="@android:color/white" />-->
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
、私はRecyclerViewを初期化し、それにデータを設定除いては何も設定されていませんでした。それが崩壊したとき
これは私が活動に
private void setDestinationRecyclerView()
{
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getBaseContext());
rcDestinations.setLayoutManager(mLayoutManager);
rcDestinations.setItemAnimator(new DefaultItemAnimator());
regionsList = new ArrayList<Region>();
destinationsAdapter = new DestinationsAdapter(regionsList,getBaseContext());
rcDestinations.setAdapter(destinationsAdapter);
//add items and notify data changed
}
をRecyclerViewを設定する方法である、どのように私はCollapsingToolbarLayoutにRecyclerViewが応答することができますか?