我是一名小白,在学习安卓,刚接触到导入外部的框架,看到github上的项目SmartRefreshLayout,就想试用一下,但配置好后一直闪退,报错日志:Unable to start activity ComponentInfo{com.zhang.hp.muke_test/com.zhang.hp.muke_test.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.scwang.smartrefresh.layout.SmartRefreshLayout,
xml文件写法:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/pull"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity写法:
tv = findViewById(R.id.text);
myrefresh = findViewById(R.id.pull);
myrefresh.setOnRefreshListener(new OnRefreshListener() {
//激活下拉刷新的时候调用的函数
@Override
public void onRefresh(RefreshLayout refreshLayout) {
tv.setText("下拉刷新了");
myrefresh.finishRefresh();
}
});
myrefresh.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(RefreshLayout refreshLayout) {
tv.setText("上拉加载了");
myrefresh.finishLoadMore();
}
});
myrefresh.setEnableLoadMore(true);
myrefresh.autoRefresh();
不知道哪里出错了,希望各位大神能指导一下,谢谢了!