LoginSignup
0
0

More than 1 year has passed since last update.

【SwipeRevealLayout】RecyclerViewの行スワイプでのメニュー表示を簡単に実装する。[Android]

Posted at

参考

https://github.com/chthai64/SwipeRevealLayout
https://www.youtube.com/watch?v=hnuMyuCWwwU&t=1236s

完成形

kanseikei.gif

今回のコード

Gradle

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>

SwipeRevealLayoutの中にlayoutを2つ配置しています。
サブ: スワイプした際に出てくる部分です。
メイン: メインのコンテンツとして表示する部分です。 
必ずサブ⇨メインの順番で記述してください。
また、app:dragEdge=""の値を変えることで上下左右どこからスワイプしてサブレイアウトを表示させるかを指定できます。

終わり

基本的には普通にRecyclerViewを使う感じで、Gradleとレイアウトファイルを少しいじるだけで実装できてしまいます。ItemTouchHelperとやらを使って実装する方法と比べて圧倒的に簡単ですよね。このOSS控えめに言って神だと思うんですが、英語かつJavaの記事ばかりだったので参考になれば幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0