android短視訊開發,仿三方軟體列表滑動

zhibo系統開發發表於2021-12-14

android短視訊開發,仿三方軟體列表滑動實現的相關程式碼

在你的佈局中新增 VastSwipeListView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
    xmlns:tools="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SlideActivity">
    <com.gcode.vastswipelayout.view.VastSwipeListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"/>
</LinearLayout>


使用 VastSwipeMenuItem 來定義你的選單項,呼叫 VastSwipeMenuMgr 內的方法將選單項新增進去

我們這裡以定義撤銷項舉例

val deleteItem = VastSwipeMenuItem(this@SlideActivity)
deleteItem.setBackgroundByColorInt(0xFF1e90ff)
deleteItem.setTitleByString("撤銷")
deleteItem.setTitleColorByColorInt(Color.WHITE)
deleteItem.setIconByResId(R.drawable.ic_delete)
deleteItem.setClickEvent { item: VastSwipeMenuItem, position: Int ->
    run {
        Toast.makeText(this@SlideActivity, "${item.title} $position", Toast.LENGTH_SHORT)
            .show()
    }
}
swipeMenuMgr.addLeftMenuItem(deleteItem)

準備列表項資料的adapter

val listViewAdapter = ListViewAdapter(this, R.layout.listview_item, lists)

將設定好的 VastSwipeMenuMgr 和列表項 Adapter 傳給 VastSwipeListView

vastSwipeListView.setSwipeMenuMgr(swipeMenuMgr)
vastSwipeListView.adapter = listViewAdapter
vastSwipeListView.onItemClickListener =
    AdapterView.OnItemClickListener { _, _, arg2, _ ->
        Toast.makeText(
            context,
            "位置   " + arg2 + "  >>>  value:" + lists[arg2],
            Toast.LENGTH_SHORT
        ).show()
    }

以上就是android短視訊開發,仿三方軟體列表滑動實現的相關程式碼, 更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2847644/,如需轉載,請註明出處,否則將追究法律責任。

相關文章