原理: ScrollView(刷新) + ListView(彈出按鈕)java
說明:因爲能力有限,刷新和滑動彈出按鈕都是第三方的library(library_pullToRefresh + library_SwipeMenuListView) 我只是整合了一下,須要的留言。。。android
圖片:ide
實現代碼:.net
1》xml:code
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/top_bar" /> <LinearLayout android:background="@drawable/login_boder_bg" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:orientation="vertical"> <!--刷新 --> <com.handmark.pulltorefresh.library.PullToRefreshScrollView android:id="@+id/scrollview" android:layout_margin="5dp" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="20dp" android:orientation="vertical"> <EditText android:gravity="center" android:layout_width="match_parent" android:layout_height="40dp" android:hint="搜索" android:background="@drawable/login_boder_bg" /> <!--彈出按鈕 --> <com.baoyz.swipemenulistview.SwipeMenuListView android:id="@+id/swipe_menu_listview" android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </com.handmark.pulltorefresh.library.PullToRefreshScrollView> </LinearLayout> </LinearLayout>
2》java:這裏只貼出核心代碼:xml
//設置ListView的高度--解決只顯示一行問題
setListViewHeight();(http://my.oschina.net/imeibi/blog/370947)
//刷新
pullToRefresh();
//建立卡片
createMenu();
//加載數據
getData();blog
1.//刷新 /** * 刷新 */ private void pullToRefresh() { pullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) { //下拉 getData(); } @Override public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) { //上拉 Message message2 = handler.obtainMessage(ONREFRESH_COMPLETE_UP); handler.sendMessage(message2); } }); }
2.//建立卡片 /** * step 1. create a MenuCreator */ private void createMenu() { SwipeMenuCreator creator = new SwipeMenuCreator() { @Override public void create(SwipeMenu menu) { // create "open" item SwipeMenuItem openItem = new SwipeMenuItem( getApplicationContext()); // set item background openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE))); // set item width openItem.setWidth(CommonUtils.dip2px(getApplicationContext(), 90)); // set item title openItem.setTitle("Open"); // set item title fontsize openItem.setTitleSize(18); // set item title font color openItem.setTitleColor(Color.WHITE); // add to menu menu.addMenuItem(openItem); // create "delete" item SwipeMenuItem deleteItem = new SwipeMenuItem( getApplicationContext()); // set item background deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25))); // set item width deleteItem.setWidth(CommonUtils.dip2px(getApplicationContext(), 90)); // set a icon deleteItem.setIcon(R.drawable.ic_delete); // add to menu menu.addMenuItem(deleteItem); } }; // set creator swipeMenuListView.setMenuCreator(creator); /** * step 2. listener item click event */ swipeMenuListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() { @Override public void onMenuItemClick(int position, SwipeMenu menu, int index) { ApplicationInfo item = mAppinfoList.get(position); switch (index) { case 0: // open // open(item); showCustomToast("打開第" + position + "個"); break; case 1: // delete // delete(item); showCustomToast("刪除第" + position + "個"); mAppinfoList.remove(position); swipeMenuListAdapter.notifyDataSetChanged(); break; } } }); // set SwipeListener swipeMenuListView.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() { @Override public void onSwipeStart(int position) { // swipe start } @Override public void onSwipeEnd(int position) { // swipe end } }); // other setting // listView.setCloseInterpolator(new BounceInterpolator()); // test item long click swipeMenuListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { showCustomToast("長按想幹嗎..."); return false; } }); }
3. //加載數據 public void getData() { Message infoMessage = handler.obtainMessage(APPLICATION_INFO); handler.sendMessage(infoMessage); }
有不足請見諒,圖片
問題:ScrollView 中嵌套listView 滑動的時候會出現衝突 你們有沒有很好的解決辦法....ip