GithubHelp home page GithubHelp logo

Comments (3)

Aspsine avatar Aspsine commented on July 24, 2024

#32

from swipetoloadlayout.

AndSync avatar AndSync commented on July 24, 2024

#32可以显示,但是我是想 在listview没有数据时候显示一个emptyView 这个emptyView 不是在listview下面 而是可以一起滑动的 可以做到吗

from swipetoloadlayout.

Aspsine avatar Aspsine commented on July 24, 2024
  • Create a Custom SwipeToLoadLayout
public class MySwipeToLoadLayout extends SwipeToLoadLayout {

    private View mTargetView;

    public MySwipeToLoadLayout(Context context) {
        super(context);
    }

    public MySwipeToLoadLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MySwipeToLoadLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setTargetView(View targetView) {
        this.mTargetView = targetView;
    }

    @Override
    protected boolean canChildScrollUp() {
        return ViewCompat.canScrollVertically(this.mTargetView, -1);
    }

    @Override
    protected boolean canChildScrollDown() {
        return ViewCompat.canScrollVertically(this.mTargetView, 1);
    }
}
  • layout
<?xml version="1.0" encoding="utf-8"?>
<com.aspsine.googlestyledemo.MySwipeToLoadLayout 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:id="@+id/swipeToLoadLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:load_more_final_drag_offset="@dimen/load_more_final_offset_google"
    app:refresh_final_drag_offset="@dimen/refresh_final_offset_google"
    app:swipe_style="classic"
    tools:context="com.aspsine.googlestyledemo.MainActivity">

    <include
        android:id="@id/swipe_refresh_header"
        layout="@layout/layout_google_hook_header" />

    <FrameLayout
        android:id="@id/swipe_target"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <ImageView
            android:id="@+id/ivEmpty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@mipmap/ic_launcher"/>
    </FrameLayout>

    <include
        android:id="@id/swipe_load_more_footer"
        layout="@layout/layout_google_hook_footer" />

</com.aspsine.googlestyledemo.MySwipeToLoadLayout>
  • activity
public class MainActivity extends AppCompatActivity implements OnRefreshListener, OnLoadMoreListener{

    MySwipeToLoadLayout swipeToLoadLayout;

    private View emptyView;

    ArrayAdapter<String> mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        swipeToLoadLayout = (MySwipeToLoadLayout) findViewById(R.id.swipeToLoadLayout);

        ListView listView = (ListView) findViewById(R.id.listView);

        emptyView = findViewById(R.id.ivEmpty);

        listView.setEmptyView(emptyView);

        // here set the listView as our new targetView
        swipeToLoadLayout.setTargetView(listView);

        swipeToLoadLayout.setOnRefreshListener(this);

        swipeToLoadLayout.setOnLoadMoreListener(this);

        mAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_expandable_list_item_1);

        listView.setAdapter(mAdapter);

        autoRefresh();
    }

    @Override
    public void onRefresh() {
        swipeToLoadLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                swipeToLoadLayout.setRefreshing(false);
                mAdapter.add("REFRESH:\n" + new Date());
            }
        }, 2000);
    }

    @Override
    public void onLoadMore() {
        swipeToLoadLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                swipeToLoadLayout.setLoadingMore(false);
                mAdapter.add("LOAD MORE:\n" + new Date());
            }
        }, 2000);
    }

    private void autoRefresh() {
        swipeToLoadLayout.post(new Runnable() {
            @Override
            public void run() {
                swipeToLoadLayout.setRefreshing(true);
            }
        });
    }
}

All done.

from swipetoloadlayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.