A swipe view for Android
SwipeView behaves like every other Android view, it supports state saving (open or closed) if an id is associated with that view.
You can specify the layout you want to use as a front_layout and the one you want to use as back_layout.
In your module build.gradle include the following dependency
implementation 'io.github.marcosignoretto:swipeview:1.1.0'<io.github.marcosignoretto.swipeview.SwipeView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>You can specify the layout resource file that you want to use as a front_layout and the one you want to use as back_layout using the appropriate xml attributes.
<io.github.marcosignoretto.swipeview.SwipeView
android:id="@+id/swipeView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:back_layout="@layout/delete_back_view"
app:front_layout="@layout/report_item_front"/>You can specify the opening size as follow:
<io.github.marcosignoretto.swipeview.SwipeView
android:id="@+id/swipeView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:opening_size="100dp"/>You can manipulate and register listeners for the view events.
To open the view programmatically use the function open()
To close the view use close() instead.
You can register a listener for the click on the front view using the normal setOnClickListener.
The click on this view is detected only when the view is in closed state.
view1.setOnClickListener(View.OnClickListener {
Toast.makeText(this, "Front view clicked", Toast.LENGTH_SHORT).show()
})If you want to handle a click on the back view you have to register a listener using setOnBackViewClickListener.
The click on this view is detected only when the view is in open state.
view1.setOnBackViewClickListener(View.OnClickListener {
Toast.makeText(this, "Back view clicked", Toast.LENGTH_SHORT).show()
})You can also register a SwipeViewListener to be notified when the view has been opened or closed.
view1.setOnSwipeViewListener(object : SwipeViewListener {
override fun onOpen() {
Toast.makeText(this@MainActivity, "View opened", Toast.LENGTH_SHORT).show()
}
override fun onClose() {
Toast.makeText(this@MainActivity, "View closed", Toast.LENGTH_SHORT).show()
}
})- Support different opening directions
