開源地址:https://github.com/open-android/DragFooterView
一個向左拖拽跳轉至更多頁面的通用控件
視頻地址:https://v.qq.com/x/page/a0383m70fzs.html
詳細的使用方法在DEMO裏面都演示啦,如果你覺得這個庫還不錯,請賞我一顆star吧~~~
歡迎關注微信公衆號、長期爲您推薦優秀博文、開源項目、視頻
微信公衆號名稱:Android乾貨程序員
自定義你自己的Footer效果
作爲一個library,當然不能只支持以上那一種效果啦,所以,這個庫的
Footer應該是可定製的,可插拔的。定製Footer只需定義一個繼承自
BaseFooterDrawer的類,然後在參數中提供的區域中繪製即可,而其餘
的事件分發,攔截都不需要關心。以下是我自己定製的兩種Footer效果。
使用步驟
1. 在project的build.gradle添加如下代碼(如下圖)
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
2. 在Module的build.gradle添加依賴
compile 'com.github.open-android:DragFooterView:0.1.0'
用法
1、在xml中配置如下 (注意:DragContainer只能有一個子View),RecyclerView向左拖拽
<com.fangxu.library.DragContainer
android:id="@+id/drag_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white" />
</com.fangxu.library.DragContainer>
2、在java類中添加事件監聽器DragListener
DragContainer dragContainer = (DragContainer) findViewById(R.id.drag_recycler_view);
//若需使用自己定製的footer,需要調用DragContainer的setFooterDrawer方法設置定製的footer類,如下
dragContainer.setFooterDrawer(new ArrowPathFooterDrawer.Builder(this, 0xff444444).setPathColor(0xffffffff).build());
dragContainer.setDragListener(new DragListener() {
@Override
public void onDragEvent() {
//do whatever you want,for example skip to the load more Activity.
Intent intent = new Intent(HomeActivity.this, ShowMoreActivity.class);
startActivity(intent);
}
});
@Override
public void onDragEvent() {
Intent intent = new Intent(HomeActivity.this, ShowMoreActivity.class);
startActivity(intent);
}
屬性
attribute | value type | defalut value | description |
---|---|---|---|
dc_footer_color | color | 0xffcdcdcd | footer view的背景顏色 |
dc_reset_animator_duration | integer | 700 | 鬆開拖拽後復位動畫的時長 |
dc_drag_damp | float | 0.5f | 拖拽阻尼係數,取值在(0,1]之間,取值越小,阻尼越大 |
* 細節注意:
//若需使用自己定製的footer,需要調用DragContainer的setFooterDrawer方法設置定製的footer類,如下
dragContainer.setFooterDrawer(new ArrowPathFooterDrawer.Builder(this, 0xff444444).setPathColor(0xffffffff).build());
其他控件用法 (HorizontalScrollView用法)
“`xml
```java
private void setupHorizontalScrollView() {
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear_layout);
for (int i = 10; i < 20; i++) {
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(dp2px(120), ViewGroup.LayoutParams.MATCH_PARENT);
params.leftMargin = 0;
params.rightMargin = dp2px(5);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(params);
linearLayout.addView(imageView);
Glide.with(this).load(Constants.urls[i]).into(imageView);
}
DragContainer dragContainer = (DragContainer) findViewById(R.id.drag_scroll_view);
BaseFooterDrawer drawer = new com.fangxu.dragfooterview.customfooters.ArrowPathFooterDrawer.Builder(this, 0xff444444).setPathColor(0xffffffff).build();
dragContainer.setFooterDrawer(drawer);
dragContainer.setDragListener(this);
}
(ImageView用法)
“`xml