I decided to try to create an animated toolbar well, that is, with a picture that falls when scrolled down. I found the source code on the Internet, with two options, tested that the first, that the second, and that in the first case, that in the second, the whole thing works, but it hangs wildly, and my phone is not ancient. However, in the same VC, everything works with a bang. Here are the source codes.

MainActivity

import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; private GridLayoutManager gridLayoutManager; private RecyclerAdapterInformation recyclerAdapterInformation; CollapsingToolbarLayout mCollapsingToolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scrolling); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); final CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.toolbar_layout); setSupportActionBar(toolbar); final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); //get the bitmap of the drawable image we are using as background Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.header); //using palette, change the color of collapsing toolbar layout Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { public void onGenerated(Palette palette) { int mutedColor = palette.getMutedColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)); int mutedDarkColor = palette.getDarkMutedColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); int vibrantColor = palette.getVibrantColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent)); collapsingToolbarLayout.setContentScrimColor(mutedColor); collapsingToolbarLayout.setStatusBarScrimColor(mutedDarkColor); fab.setBackgroundTintList(ColorStateList.valueOf(vibrantColor)); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 

activity_main.xml

  <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/header" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> 

  • 100500% your head picture is heavy - Flippy
  • how to understand heavy? size or quality is high? or length? - Dimantik02
  • 2
    Well figs I know him once with this problem all day nerves spoiled. The picture turned out to be the wrong one, I can’t explain it in the graphics, I can only say that everything was twitching on the screen. The picture weighed 80kb. Materialdesign, clear. Changed to a primitive, 300kb, it seems to weigh more, but the problem has disappeared. Since you are the code, then the problem is just that. - Flippy

0