1.打开 Project root 的 build.gradle
allprojects { repositories { ... maven { url "https://jitpack.io" } } }
2.增加dependency
dependencies { compile 'com.github.quanke:AndroidEmptyLayout:v1.0.0' }
3.在布局文件里增加
<name.quanke.app.libs.emptylayout.EmptyLayout android:id="@+id/emptyLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textHello" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> </name.quanke.app.libs.emptylayout.EmptyLayout>
4.代码里增加:
findViewById(R.id.btnLoading).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { emptyLayout.showLoading(); } }); findViewById(R.id.btnEmpty).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { emptyLayout.showEmpty(); } }); findViewById(R.id.btnError).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { emptyLayout.showError(); } }); findViewById(R.id.btnData).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { emptyLayout.hide(); } });