toolBar + Image を折りたたんで最小の高さに固定しようとしています。うまくいかないので、コードを投稿します。どんな助けでも大歓迎です。
以下のリンクを参考にしてください
http://blog.grafixartist.com/toolbar-animation-with-android-design-support-library/
以下は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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
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:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<!-- app:layout_collapseMode="pin"
-->
<ImageView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/header"
android:fitsSystemWindows="true"
android:minHeight="100dp"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/scrollableview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
クラスコードは
public class GroupChatDetailsActivity extends AppCompatActivity {
int mutedColor = R.attr.colorPrimary;
GroupChatDetailsAdapter groupChatDetailsAdapter;
private CollapsingToolbarLayout collapsingToolbar;
private RecyclerView recyclerView;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.group_details_layout);
setup ();
}
private void setup () {
Toolbar toolbar = (Toolbar) findViewById (R.id.anim_toolbar);
setSupportActionBar (toolbar);
getSupportActionBar ().setDisplayHomeAsUpEnabled (true);
collapsingToolbar = (CollapsingToolbarLayout) findViewById (R.id.collapsing_toolbar);
collapsingToolbar.setTitle ("Test Title");
ImageView header = (ImageView) findViewById (R.id.header);
Bitmap bitmap = BitmapFactory.decodeResource (getResources (),
R.drawable.header);
Palette.from (bitmap).generate (new Palette.PaletteAsyncListener () {
@SuppressWarnings ("ResourceType")
@Override
public void onGenerated (Palette palette) {
mutedColor = palette.getMutedColor (R.color.primary_500);
collapsingToolbar.setContentScrimColor (mutedColor);
collapsingToolbar.setStatusBarScrimColor (R.color.black_trans80);
}
});
recyclerView = (RecyclerView) findViewById (R.id.scrollableview);
recyclerView.setHasFixedSize (true);
LinearLayoutManager layoutManager
= new LinearLayoutManager (this);
recyclerView.setLayoutManager (layoutManager);
List<String> listData = new ArrayList<String> ();
int ct = 0;
for (int i = 0; i < VersionModel.data.length * 2; i++) {
listData.add (VersionModel.data[ct]);
ct++;
if (ct == VersionModel.data.length) {
ct = 0;
}
}
if (groupChatDetailsAdapter == null) {
groupChatDetailsAdapter = new GroupChatDetailsAdapter (listData);
recyclerView.setAdapter (groupChatDetailsAdapter);
}
}
}