這篇文章給大家介紹Android應(yīng)用中的標(biāo)題滾動效果怎么利用Support Library 實現(xiàn),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
成都創(chuàng)新互聯(lián)公司專注于桐梓企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),商城網(wǎng)站開發(fā)。桐梓網(wǎng)站建設(shè)公司,為桐梓等地區(qū)提供建站服務(wù)。全流程按需定制設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
布局文件代碼
在布局文件中,CoordinatorLayout作為布局文件根節(jié)點,AppBarLayout包含在CoordinatorLayout中,toolbar在AppBarLayout節(jié)點下include進(jìn)來。
<?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" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="cn.manchester.androidsupportlibrary.CoordinatorLayoutActivity"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <include layout="@layout/toolbar" /> </android.support.design.widget.AppBarLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:scrollbars="none" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </android.support.design.widget.CoordinatorLayout>
toolbar.xml
toolbar是需要響應(yīng)view的滾動事件的,所以需要為toolbar指定layout_scrollFlags屬性,scroll表示toobar會隨著view的向下滾動而隱藏,enterAlways表示toolbar會隨著view的向上滾動而恢復(fù)到原來的位置。
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#304696" android:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:layout_scrollFlags="scroll|enterAlways" app:theme="@style/ThemeOverlay.AppCompat.ActionBar"> </android.support.v7.widget.Toolbar>
Java代碼
public class CoordinatorLayoutActivity extends AppCompatActivity { Toolbar mToolbar; RecyclerView mRecyclerView; String[] mArrays = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_coordinator_layout); mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mRecyclerView.setAdapter(new MyAdapter()); } class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> { @Override public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { MyViewHolder holder = new MyViewHolder(LayoutInflater.from(CoordinatorLayoutActivity.this) .inflate(android.R.layout.simple_list_item_1, parent, false)); return holder; } @Override public void onBindViewHolder(MyAdapter.MyViewHolder holder, int position) { holder.tv.setText(mArrays[position]); } @Override public int getItemCount() { return mArrays.length; } class MyViewHolder extends RecyclerView.ViewHolder { TextView tv; public MyViewHolder(View itemView) { super(itemView); tv = (TextView) itemView.findViewById(android.R.id.text1); } } } }
關(guān)于Android應(yīng)用中的標(biāo)題滾動效果怎么利用Support Library 實現(xiàn)就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
網(wǎng)頁題目:Android應(yīng)用中的標(biāo)題滾動效果怎么利用SupportLibrary實現(xiàn)
標(biāo)題路徑:http://chinadenli.net/article24/jsihje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站排名、網(wǎng)頁設(shè)計公司、移動網(wǎng)站建設(shè)、營銷型網(wǎng)站建設(shè)、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)