Andorid Scrolling Activity (CoordinatorLayout details), scrollingactivity

Source: Internet
Author: User

Andorid Scrolling Activity (CoordinatorLayout details), scrollingactivity
1. new project-> Scrolling Activity2.Layout xml codeactivity_scrolling.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     xmlns:app="http://schemas.android.com/apk/res-auto" 4     xmlns:tools="http://schemas.android.com/tools" 5     android:layout_width="match_parent" 6     android:layout_height="match_parent" 7     android:fitsSystemWindows="true" 8     tools:context="com.eve.coordinatorlayoutsample.ScrollingActivity"> 9 10     <android.support.design.widget.AppBarLayout11         android:id="@+id/app_bar"12         android:layout_width="match_parent"13         android:layout_height="@dimen/app_bar_height"14         android:fitsSystemWindows="true"15         android:theme="@style/AppTheme.AppBarOverlay">16 17         <android.support.design.widget.CollapsingToolbarLayout18             android:id="@+id/toolbar_layout"19             android:layout_width="match_parent"20             android:layout_height="match_parent"21             android:fitsSystemWindows="true"22             app:contentScrim="?attr/colorPrimary"23             app:layout_scrollFlags="scroll|exitUntilCollapsed">24 25             <android.support.v7.widget.Toolbar26                 android:id="@+id/toolbar"27                 android:layout_width="match_parent"28                 android:layout_height="?attr/actionBarSize"29                 app:layout_collapseMode="pin"30                 app:popupTheme="@style/AppTheme.PopupOverlay" />31 32             <ImageView33                 android:src="@mipmap/bird"34                 app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"35                 android:layout_width="match_parent"36                 android:layout_height="match_parent"37                 android:scaleType="centerCrop"38                 app:layout_collapseMode="parallax"39                 android:minHeight="?attr/actionBarSize"/>40 41         </android.support.design.widget.CollapsingToolbarLayout>42     </android.support.design.widget.AppBarLayout>43 44     <include layout="@layout/content_scrolling" />45 46     <android.support.design.widget.FloatingActionButton47         android:id="@+id/fab"48         android:layout_width="wrap_content"49         android:layout_height="wrap_content"50         android:layout_margin="@dimen/fab_margin"51         app:layout_anchor="@id/app_bar"52         app:layout_anchorGravity="bottom|end"53         app:srcCompat="@android:drawable/ic_dialog_email" />54 55 </android.support.design.widget.CoordinatorLayout>

 

Content_scrolling.xml
 1 <?xml version="1.0" encoding="utf-8"?> 2 <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 3     xmlns:app="http://schemas.android.com/apk/res-auto" 4     xmlns:tools="http://schemas.android.com/tools" 5     android:layout_width="match_parent" 6     android:layout_height="match_parent" 7     app:layout_behavior="@string/appbar_scrolling_view_behavior" 8     tools:context="com.eve.coordinatorlayoutsample.ScrollingActivity" 9     tools:showIn="@layout/activity_scrolling">10 11     <TextView12         android:layout_width="wrap_content"13         android:layout_height="wrap_content"14         android:layout_margin="@dimen/text_margin"15         android:text="@string/large_text" />16 17 </android.support.v4.widget.NestedScrollView>

 

3. Activity code
 1 public class ScrollingActivity extends AppCompatActivity { 2  3     @Override 4     protected void onCreate(Bundle savedInstanceState) { 5         super.onCreate(savedInstanceState); 6         setContentView(R.layout.activity_scrolling); 7         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 8         setSupportActionBar(toolbar); 9 10         FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);11         fab.setOnClickListener(new View.OnClickListener() {12             @Override13             public void onClick(View view) {14                 Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)15                         .setAction("Action", null).show();16             }17         });18     }19 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.