How to put image in CollapsingToolbarLayout
Inside of our CollopasingTollbarLayout you can put our Image and Toolbar.
you can check in GitHub
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <? xml version = "1.0" encoding = "utf-8" ?> < android.support.design.widget.CoordinatorLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent" android:layout_height = "match_parent" android:fitsSystemWindows = "true" tools:context = "com.thedeveloperworldisyours.imagecollapsingtoolbarlayout.ScrollingActivity" > < android.support.design.widget.AppBarLayout android:id = "@+id/app_bar" android:layout_width = "match_parent" android:layout_height = "@dimen/app_bar_height" android:fitsSystemWindows = "true" android:theme = "@style/AppTheme.AppBarOverlay" > < android.support.design.widget.CollapsingToolbarLayout android:id = "@+id/toolbar_layout" android:layout_width = "match_parent" android:layout_height = "match_parent" android:fitsSystemWindows = "true" app:contentScrim = "?attr/colorPrimary" app:layout_scrollFlags = "scroll|exitUntilCollapsed" > <!--image--> < ImageView android:layout_width = "match_parent" android:layout_height = "match_parent" android:src = "@drawable/scardface_scrolling" /> <!--toolbar--> < 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 > < include layout = "@layout/content_scrolling" /> </ android.support.design.widget.CoordinatorLayout > |
In our content
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <? xml version = "1.0" encoding = "utf-8" ?> < android.support.v4.widget.NestedScrollView xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent" android:layout_height = "match_parent" app:layout_behavior = "@string/appbar_scrolling_view_behavior" tools:context = "com.thedeveloperworldisyours.imagecollapsingtoolbarlayout.ScrollingActivity" tools:showIn = "@layout/activity_scrolling" > < TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_margin = "@dimen/text_margin" android:text = "@string/large_text" /> </ android.support.v4.widget.NestedScrollView > |
In our activity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public class ScrollingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_scrolling); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); } @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_scrolling, 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); } } |