Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android 簡單實現ListView頂部懸浮效果

Android 簡單實現ListView頂部懸浮效果

編輯:關於Android編程

首先上效果圖,實現如下效果:

\



<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+xvCz9dTazfjJz8vRwcvPwsq1z9bV4tH5tcTQp7n7o6zDwM3FzfgstPPW2rXjxsC1xKGwubrC8r/yobHQ/Lih0Ke5+9KyysfV4tH5tcSjrLK7uf3X99XfyrXP1rHIvc/C6bezo6zX1Ly6z+vBy8/rvs24+b7dTGlzdFZpZXfM4bmptcTSu9CpzNjQ1L340NDBy7zytaXKtc/WoaM8L3A+CjxwPtX7uPbW99Kqsry+1r7NysfSu7j2TGlzdFZpZXejrMjnuftsaXN0dmlld7XEyc/D5tPQxNrI3cfSuN+2yLHIvc+436Osv8nS1LDRy/y1sdf2bGlzdHZpZXe1xGhlYWRlcqOs1eLR+dKyv8nS1LHcw+JTY3JvbGxWaWV3x7bM10xpc3RWaWV3tPjAtLXEwum3s6OovMfXodXi0ru1477Nsru74dTaxr3KsbP2z9ZTY3JvbGxWaWV30+tMaXN0Vmlld7j31tbOysziwcujqaGj0qrKtc/W0Py4odCnufujrNb30qrKx7j5vt1MaXN0Vmlld7/JvPu1xLXa0ru49sz1xL/Kx8TEuPbM9cS/wLSy2df3tcSho9ei0uLV4sDvtcShsND8uKGhscbkyrXWu8rHzai5/SDS/rLYL8/Uyr4g0Py4obK/t9bAtMq1z9ajutTaTGlzdFZpZXehsLGzuvOhsdPQ0ru49tL+sti1xKGw0Py4obK/t9ahsaOstbFMaXN0Vmlld8z1xL/W0LXE0Py4obK/t9azyc6qTGlzdFZpZXe/ybz7sr+31rXa0ru49sqxo6zV4sqxt8dMaXN0Vmlld8z1xL/W0LXE0Py4obK/t9bP1Mq+s/bAtKOs1eLR+dTss8mhsND8uKGhsbK/t9bSu9ax1Nq2pbK/uKG2r6OstbFMaXN0Vmlld7/JvPuyv7fWtdrSu7j2zPXEv7KisrvKx9D8uKHKsaOst8dMaXN0Vmlld8THsr+31qGw0v6y2LK/t9ahsbzM0PjS/rLYoaOx7bTvxNzBprK7x7+jrNfUvLq2vL/ssbvX1Ly6yMbUzsHLo6zX3Nauvs3KxzK49tD8uKGyv7fWo7pMaXN0Vmlld8z1xL/W0LXEus20ptPasry+1ralsr/S/rLYo6hHb25lL2ludmlzaWJsZaOptcTG8LP1zrTP1Mq+tcSjrM2ouf3V4sG9sr+31rXEstnX98C0zeqzydX7uPa5psTctcSho8+jzfu2wdXfxNy5u8DtveKhraGtPC9wPgo8cD7W99KqtPrC66O6PC9wPgo8cD48cHJlIGNsYXNzPQ=="brush:java;">@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sticky); invis = (LinearLayout) findViewById(R.id.invis); strs = new String[100]; for (int i = 0; i < 20; i++) { strs[i] = "data-----" + i; } lv = (ListView) findViewById(R.id.lv); View header = View.inflate(this, R.layout.stick_header, null);//頭部內容 lv.addHeaderView(header);//添加頭部 lv.addHeaderView(View.inflate(this, R.layout.stick_action, null));//ListView條目中的懸浮部分 添加到頭部 lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, strs)); lv.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) { if (firstVisibleItem >= 1) { invis.setVisibility(View.VISIBLE); } else { invis.setVisibility(View.GONE); } } }); }


布局:




    

    <frameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title" >

        

        

            
        
    </frameLayout>


代碼下載地址:http://download.csdn.net/download/ljfbest/7804769

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved