最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SwipeLayout框架實(shí)現(xiàn)側(cè)拉刪除編輯功能

 更新時(shí)間:2018年08月17日 15:27:10   作者:chenlxhf  
這篇文章主要為大家詳細(xì)介紹了SwipeLayout框架實(shí)現(xiàn)側(cè)拉刪除編輯功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了SwipeLayout實(shí)現(xiàn)側(cè)拉刪除編輯的具體代碼,供大家參考,具體內(nèi)容如下

第一步、添加依賴

dependencies {
  compile 'com.android.support:recyclerview-v7:21.0.0'
  compile 'com.android.support:support-v4:20.+'
  compile "com.daimajia.swipelayout:library:1.2.0@aar"
}

第二步、布局文件

//建議最好是在BottomView里面添加layout_gravity屬性,或者在代碼里面添加
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="80dp">
<!-- Bottom View Start-->
 <LinearLayout
  android:background="#66ddff00"
  android:id="@+id/bottom_wrapper"
  android:layout_width="160dp"
  android:weightSum="1"
  android:layout_height="match_parent">
  <!--What you want to show-->
  <!--在這里寫我們側(cè)滑后顯示出來(lái)的控件-->
  <!-通常是幾個(gè)TextView或者Button--->
</LinearLayout>
<!-- Bottom View End-->

<!-- Surface View Start -->
 <LinearLayout
  android:padding="10dp"
  android:background="#ffffff"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <!--What you want to show in SurfaceView-->
  <!--這里寫我們條目顯示的內(nèi)容的布局-->
</LinearLayout>
<!-- Surface View End -->
</com.daimajia.swipe.SwipeLayout>

第三步、在Activity中得到SwipeLayout實(shí)例.

SwipeLayout swipeLayout = (SwipeLayout) view.findViewById(R.id.swipelayout);
  //設(shè)置側(cè)拉的模式
  swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
  //如果布局文件里面有l(wèi)ayout_gravity屬性,這句可以忽略
  //swipeLayout.addDrag(SwipeLayout.DragEdge.Left, findViewById(R.id.bottom_wrapper));

到此為止,一個(gè)條目的側(cè)滑功能就實(shí)現(xiàn)了。
如果我們?cè)贚istview里面使用這個(gè)功能,那么我們需要繼承BaseSwipeAdapter,并且復(fù)寫里面的幾個(gè)方法:

//獲取swipeLayout布局
 @Override
public int getSwipeLayoutResourceId(int position) {
  return R.id.swipelayout;
}

//生成條目布局,相當(dāng)于BaseAdapter里面的getView()方法
@Override
public View generateView(int position, ViewGroup parent) {
  View view = LayoutInflater.from(mContext).inflate(R.layout.listview_item, null);
  SwipeLayout swipeLayout = (SwipeLayout) view.findViewById(R.id.swipelayout);
  //這里寫對(duì)布局中控件的一些初始化
  swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);    
  return view;
}
//為條目里面的控件賦值
@Override
public void fillValues(int position, View convertView) {

}
//下面的幾個(gè)方法是BaseAdapter里面的方法,BaseSwipeAdapter也是繼承自BaseAdapter
@Override
public int getCount() {
  return 0;
}

@Override
public Object getItem(int i) {
  return null;
}

@Override
public long getItemId(int i) {
  return 0;
}

這樣,一個(gè)ListView的條目側(cè)滑就基本實(shí)現(xiàn)了。點(diǎn)擊刪除/編輯的代碼我們?cè)诜椒╣enerateView()里面實(shí)現(xiàn)。下面為L(zhǎng)istview添加條目點(diǎn)擊事件:

//此處的swipeLayout是generateView()里面從條目布局里面獲取的
swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

    }
});

如果我們需要在側(cè)滑的時(shí)候?qū)崿F(xiàn)其他邏輯的話,我們可以添加側(cè)滑監(jiān)聽:

swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
 @Override
 public void onClose(SwipeLayout layout) {
  //when the SurfaceView totally cover the BottomView.
 }

 @Override
 public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
  //you are swiping.
 }

 @Override
 public void onStartOpen(SwipeLayout layout) {

 }

 @Override
 public void onOpen(SwipeLayout layout) {
  //when the BottomView totally show.
 }

 @Override
 public void onStartClose(SwipeLayout layout) {

 }

 @Override
 public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
  //when user's hand released.
 }
});

到此,ListView側(cè)滑功能基本實(shí)現(xiàn)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實(shí)現(xiàn)文件上傳和下載倒計(jì)時(shí)功能的圓形進(jìn)度條

    Android實(shí)現(xiàn)文件上傳和下載倒計(jì)時(shí)功能的圓形進(jìn)度條

    這篇文章主要介紹了Android實(shí)現(xiàn)文件上傳和下載倒計(jì)時(shí)功能的圓形進(jìn)度條,需要的朋友可以參考下
    2017-09-09
  • Android中Java instanceof關(guān)鍵字全面解析

    Android中Java instanceof關(guān)鍵字全面解析

    instanceof關(guān)鍵字用于判斷一個(gè)引用類型變量所指向的對(duì)象是否是一個(gè)類(或接口、抽象類、父類)的實(shí)例.這篇文章主要介紹了Android中Java instanceof關(guān)鍵字全面解析的相關(guān)資料,需要的朋友可以參考下
    2016-07-07
  • 如何通過(guò)Android Logcat插件分析firebase崩潰問(wèn)題

    如何通過(guò)Android Logcat插件分析firebase崩潰問(wèn)題

    android crash Crash(應(yīng)用崩潰)是由于代碼異常而導(dǎo)致App非正常退出,導(dǎo)致應(yīng)用程序無(wú)法繼續(xù)使用,所有工作都停止的現(xiàn)象,本文重點(diǎn)介紹如何通過(guò)Android Logcat插件分析firebase崩潰問(wèn)題,感興趣的朋友一起看看吧
    2024-01-01
  • Android編程實(shí)現(xiàn)調(diào)用系統(tǒng)分享功能示例

    Android編程實(shí)現(xiàn)調(diào)用系統(tǒng)分享功能示例

    這篇文章主要介紹了Android編程實(shí)現(xiàn)調(diào)用系統(tǒng)分享功能,結(jié)合實(shí)例形式分析了Android實(shí)現(xiàn)針對(duì)文字、圖片等元素分享功能的相關(guān)操作技巧,需要的朋友可以參考下
    2017-01-01
  • Android事件的分發(fā)機(jī)制詳解

    Android事件的分發(fā)機(jī)制詳解

    這篇文章主要為大家詳細(xì)介紹了Android事件的分發(fā)機(jī)制,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Android讀寫文件工具類詳解

    Android讀寫文件工具類詳解

    這篇文章主要為大家詳細(xì)介紹了Android讀寫文件工具類,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • Flutter?runApp到渲染上屏分析詳解

    Flutter?runApp到渲染上屏分析詳解

    這篇文章主要為大家介紹了Flutter?runApp到渲染上屏分析詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • Android給布局、控件加陰影效果的示例代碼

    Android給布局、控件加陰影效果的示例代碼

    本篇文章主要介紹了Android給布局、控件加陰影效果的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • 關(guān)于Android多渠道打包的進(jìn)階知識(shí)

    關(guān)于Android多渠道打包的進(jìn)階知識(shí)

    前一篇文章主要介紹了關(guān)于Android程序的多渠道打包方法,這一篇文章介紹了多渠道打包的進(jìn)階知識(shí),還不會(huì)的同學(xué)快進(jìn)來(lái)學(xué)習(xí)下吧,建議收藏以防迷路
    2021-08-08
  • Android Studio 下載視頻到本地

    Android Studio 下載視頻到本地

    這篇文章主要介紹了Android Studio 下載視頻到本地,利用GreenDao實(shí)現(xiàn)多線程斷點(diǎn)續(xù)傳,這樣的話,下次用戶再次下載時(shí),將繼續(xù)上次數(shù)據(jù)庫(kù)的接著下載,這樣用戶體驗(yàn)就會(huì)很好,也大大節(jié)省了成本.具體實(shí)現(xiàn)代碼大家參考下本文
    2018-03-03

最新評(píng)論

革吉县| 闽清县| 蓬莱市| 凤阳县| 梅州市| 贡觉县| 九龙县| 石棉县| 自贡市| 兴宁市| 双鸭山市| 营山县| 桂阳县| 武冈市| 高安市| 定远县| 阿拉善盟| 宜宾市| 汪清县| 吉木乃县| 临湘市| 甘谷县| 诸城市| 玛多县| 孟州市| 东丽区| 紫金县| 玛纳斯县| 金山区| 拜城县| 曲阜市| 广平县| 营口市| 辽源市| 武平县| 绥德县| 赤峰市| 栖霞市| 涟水县| 美姑县| 亳州市|