SmartRefreshLayout:https://github.com/scwang90/SmartRefreshLayout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main25Activity">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
app:srlAccentColor="@android:color/white">
<com.scwang.smartrefresh.layout.header.TwoLevelHeader
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/second_floor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"
android:src="@mipmap/image_second_floor" />
<FrameLayout
android:id="@+id/second_floor_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:background="#fff">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name"
android:gravity="center"
android:scaleType="centerCrop"
android:text="二楼"
android:textColor="#000000" />
</FrameLayout>
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:id="@+id/classics"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smartrefresh.layout.header.TwoLevelHeader>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:fillViewport="true"
android:overScrollMode="never">
<RelativeLayout
android:id="@+id/contentPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
android:gravity="center"
android:text="内容主题"
android:textColor="#000"
android:textSize="20dp" />
</RelativeLayout>
</ScrollView>
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
</FrameLayout>
public class Main25Activity extends AppCompatActivity {
private TwoLevelHeader header;
private RefreshLayout refreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main25);
initView();
refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
Toast.makeText(getApplication(),"上拉加载",Toast.LENGTH_SHORT).show();
refreshLayout.finishLoadMore(2000);
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
Toast.makeText(getApplication(),"下拉刷新",Toast.LENGTH_SHORT).show();
refreshLayout.finishRefresh(2000);
}
@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
if (oldState == RefreshState.TwoLevel){
findViewById(R.id.second_floor_content).animate().alpha(0).setDuration(1000);
}
}
});
header.setOnTwoLevelListener(new OnTwoLevelListener() {
@Override
public boolean onTwoLevel(@NonNull RefreshLayout refreshLayout) {
Toast.makeText(getApplication(),"打开二楼",Toast.LENGTH_SHORT).show();
findViewById(R.id.second_floor_content).animate().alpha(1).setDuration(2000);
return true;
}
});
}
private void initView() {
header=findViewById(R.id.header);
refreshLayout = findViewById(R.id.refreshLayout);
}
}
网友评论