Learning from projects: https://github.com/nanchen2251/AiYaGirl
By the background image on the slide hidden
Take a look
After sliding navigation bar on the navigation bar extended contraction state
Realization of ideas
To achieve this effect, we need to use: with CoordinatorLayout and AppbarLayout, as well as to achieve a NestedScrollView layout or control.
AppbarLayout is a support response scrolling gesture app bar layout,
CollapsingToolbarLayout is designed to achieve a different response elements within the scroll details of the layout of the sub-layout.
The layout of the combined AppbarLayout (RecyclerView, NestedScrollView etc.) need to be set app: layout_behavior = "@ string / appbar_scrolling_view_behavior". If not set, AppbarLayout will not respond to events scroll scrolling layout.
This layout behavior Layout_Behavior: `app: layout_behavior =" @ string / appbar_scrolling_view_behavior "`
is equivalent to the `app: layout_behavior =" android.support.design.widget.AppBarLayout $ ScrollingViewBehavior "`
This is a system behavior, it is to set a rolling action to appbar behavior. Without this attribute, then, Appbar is dead, it has been the soul.
Main layout layout \ activity_nav_home.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:background="#f2f4f5"> <android.support.design.widget.AppBarLayout android:id="@+id/nav_home_appbar" android:layout_width="match_parent" android:layout_height="210dp" app:theme="@style/Base.ThemeOverlay.AppCompat.Dark"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/nav_home_toolbarLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="@color/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" app:title="理查德·费曼"> <ImageView android:id="@+id/nav_home_image" android:layout_width="match_parent" android:layout_height="match_parent" android:contentDescription="@null" android:scaleType="fitXY" android:src="@mipmap/richard_phillips_feynman" /> <android.support.v7.widget.Toolbar android:id="@+id/nav_home_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:navigationIcon="@mipmap/icon_back" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:id="@+id/nav_home_nestedScrollView" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="10dp" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="理查德·费曼" android:textColor="#ff333333" android:textSize="16sp" /> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginRight="8dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:autoLink="web" android:background="#ffffffff" android:lineSpacingExtra="3dp" android:padding="7dp" android:text="@string/about_richard_phillips_feynman" android:textColor="#666" android:textIsSelectable="true" /> </android.support.v7.widget.CardView> </LinearLayout> </android.support.v4.widget.NestedScrollView> <!--悬浮按钮:分享--> <android.support.design.widget.FloatingActionButton android:id="@+id/nav_home_fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:src="@mipmap/actionbar_share" app:layout_anchor="@id/nav_home_appbar" app:layout_anchorGravity="bottom|end" /> </android.support.design.widget.CoordinatorLayout>
Main page Code NavHomeActivity.java
public class NavHomeActivity the extends AppCompatActivity { @BindView (R.id.nav_home_toolbar) Toolbar mToolBar; @BindView (R.id.nav_home_fab) FloatingActionButton mFab; @Override protected void the onCreate (@Nullable the Bundle savedInstanceState) { Super .onCreate (savedInstanceState); the setContentView (R.layout.activity_nav_home); ButterKnife.bind ( the this ); as initView (); } Private void as initView () { // integrated with background status bar (StatusBarUtil class 'image rotation Banner have described') StatusBarUtil. setTranslucentForImageView ( the this , 0, MToolBar); // navigation bar settings setSupportActionBar (mToolBar); getSupportActionBar () setHomeButtonEnabled (. To true ); getSupportActionBar () setDisplayHomeAsUpEnabled (. To true ); // navigation bar navigation buttons: Return mToolBar.setNavigationOnClickListener ( new new View.OnClickListener ( ) { @Override public void the onClick (View V) { Finish (); } }); } // share button @OnClick (R.id.nav_home_fab) public void onViewClicked () { ShareUtil.share ( the this , R.string. string_share_text); } }
Share Tools ShareUtil.java
import android.content.Context; import android.content.Intent; import android.net.Uri; import com.zss.pp.R; /** * 专用于分享的工具类 */ public class ShareUtil { public static void share(Context context, int stringRes) { share(context, context.getString(stringRes)); } public static void shareImage(Context context, Uri uri, String title) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/jpeg"); context.startActivity(Intent.createChooser(shareIntent, title)); } public static void share(Context context, String extraText) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.action_share)); intent.putExtra(Intent.EXTRA_TEXT, extraText); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(Intent.createChooser(intent, context.getString(R.string.action_share))); } }
Resource requirements
- Share icon actionbar_share
- Back icon icon_back
- Text display
< String name = "action_share" > Share </ String > < String name = "string_share_text" > share Feynman's thinking: https: //www.sohu.com/a/197127933_464074 [small share of self-love exciting moment] </ String > < String name = "about_richard_phillips_feynman" > omitted by ...... n \ n blocks of text segment to \ </ String >