【SwipeRevealLayout】RecyclerViewの行スワイプでのメニュー表示を簡単に実装する。[Android]
参考
https://github.com/chthai64/SwipeRevealLayout
https://www.youtube.com/watch?v=hnuMyuCWwwU&t=1236s
完成形
今回のコード
Gradle
dependencies {
compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
}
dependencies {
compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
}
ちなみに'compile'は非推奨とされていて、代わりに'api'や'implementation'が推奨されています。
行ごとのレイアウト
item_swipe_recycler.xml
<com.chauthai.swipereveallayout.SwipeRevealLayout
android:layout_width="match_parent"
android:layout_height="60dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
app:mode="same_level"
app:dragEdge="right">
//サブ
<LinearLayout...>
//メイン
<androidx.constraintlayout.widget.ConstraintLayout...>
</com.chauthai.swipereveallayout.SwipeRevealLayout>
item_swipe_recycler.xml
<com.chauthai.swipereveallayout.SwipeRevealLayout
android:layout_width="match_parent"
android:layout_height="60dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
app:mode="same_level"
app:dragEdge="right">
//サブ
<LinearLayout...>
//メイン
<androidx.constraintlayout.widget.ConstraintLayout...>
</com.chauthai.swipereveallayout.SwipeRevealLayout>
SwipeRevealLayoutの中にlayoutを2つ配置しています。
サブ: スワイプした際に出てくる部分です。
メイン: メインのコンテンツとして表示する部分です。
必ずサブ⇨メインの順番で記述してください。
また、app:dragEdge=""の値を変えることで上下左右どこからスワイプしてサブレイアウトを表示させるかを指定できます。
終わり
基本的には普通にRecyclerViewを使う感じで、Gradleとレイアウトファイルを少しいじるだけで実装できてしまいます。ItemTouchHelperとやらを使って実装する方法と比べて圧倒的に簡単ですよね。このOSS控えめに言って神だと思うんですが、英語かつJavaの記事ばかりだったので参考になれば幸いです。
Author And Source
この問題について(【SwipeRevealLayout】RecyclerViewの行スワイプでのメニュー表示を簡単に実装する。[Android]), 我々は、より多くの情報をここで見つけました https://qiita.com/RiutaDaiki/items/5146eb178d65ca849f68著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .