Android Studio-New-Import Module
build.gradle
dependencies {
implementation project(':SwipeLayoutLibrary-master')
}
settings.gradle
include ':app', ':SwipeLayoutLibrary-master'<com.lyml.SwipeLayout xmlns:sl="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
sl:defaultView="1"
sl:defaultViewWidthRealMatchParent="true"
sl:scrollState="normal">
...
</com.lyml.SwipeLayout>- 布局内部不限制View个数
- defaultView: 默认View的索引,默认View即主要的View
- defaultViewWidthRealMatchParent:可填true/false,默认false。 默认View是否充满布局(如果默认View的位置不为0,仅对默认View使用android:layout_width="match_parent"不能达到预期效果)
- scrollState:可填left/normal/right,默认normal 默认的滚动位置
- 超出屏幕外的控件需要使用固定宽度,否则会不显示
public static final int SCROLL_STATE_NORMAL = 0;// 滚动到默认View
public static final int SCROLL_STATE_LEFT = 1;// 滚动到默认View左边
public static final int SCROLL_STATE_RIGHT = 2;// 滚动到默认View右边/**
* 获得当前状态
* @return
*/
public int getScrollState()
/**
* 切换到状态
* @param scrollState
*/
public void setScrollState(int scrollState)
/**
* 平滑滚动到状态
* @param scrollState
*/
public void smoothScrollToState(int scrollState)public interface OnSwipedListener {
/**
* 状态改变事件
* @param state 改变后状态
* @param stateOld 改变前状态
*/
void onSwiped(int state, int stateOld);
/**
* 滚动事件
* @param state 滚动状态
* @param stateOffset 滚动百分比
* @param stateOffsetPixels 滚动像素
*/
void onScrolled(int state,float stateOffset,int stateOffsetPixels);
}