我试图在片段中实现SwipeRefreshLayout。它看起来正确,但我继续得到错误:
Caused by: android.view.InflateException: Binary XML file line #2:
Binary XML file line #2: Error inflating class
android.support.v4.widget.SwipeRefreshLayout
Caused by: android.view.InflateException: Binary XML file line #2:
Error inflating class android.support.v4.widget.SwipeRefreshLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class
"android.support.v4.widget.SwipeRefreshLayout" on path:
DexPathList[[zip file "/data/app/com.weather.rainy-
2/base.apk"],nativeLibraryDirectories=[/data/app/com.weather.rainy-
2/lib/x86, /system/lib, /vendor/lib]]
我真的不知道造成这种情况的原因。
我的片段布局用于实现SwipeRefreshLayout:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipeToRefresh4Maps"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/topRL4Maps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_gradient_purple"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="64dp"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="64dp"
tools:context="com.weather.rainy.ui.MapsActivity">
<TextView
android:id="@+id/yourLocationLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="@+string/your_location"
android:textColor="@android:color/white"
android:textSize="24sp" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/addressValueTextView"
android:layout_alignBottom="@+id/addressValueTextView"
android:layout_below="@+id/yourLocationLabelTextView"
android:layout_centerHorizontal="true"
android:layout_margin="15dp"
tools:context="com.weather.rainy.ui.MapsActivity" />
<TextView
android:id="@+id/addressValueTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/map"
android:layout_alignEnd="@+id/map"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="true"
android:text="@+string/..."
android:textColor="#aaffffff"
android:textSize="18sp" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
而且,我的片段类用于调用SwipeRefreshLayout:
//Code for Swipe Refresh
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh4Maps);
mSwipeRefreshLayout.setColorSchemeResources(R.color.Red, R.color.Orange, R.color.Blue, R.color.Green);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Log.v(TAG, "************** MAPS - SWIPE REFRESH EVENT TRIGGERED!!!!!");
findLocation();
}
});
我真的没有任何线索,有什么不对。任何帮助是极大的赞赏。
因为您使用的是AndroidX,所以您的XML引用了错误版本的SwipeRefreshLayout
将XML从android.support.v4.widget.SwipeRefreshLayout
更改为androidx.swiperefreshlayout.widget.SwipeRefreshLayout
迁移到AndroidX时似乎会发生此问题,因为在迁移到AndroidX时需要更改许多构建工件。
例如:
android.support.v4.widget.SwipeRefreshLayout
改为=> androidx.swiperefreshlayout.widget.SwipeRefreshLayout
您必须更新Migrating to AndroidX中列出的所有构建工件
正如在同一链接中所建议的那样,您可以通过从菜单栏中选择Refactor> Migrate to AndroidX来自动执行此过程。
附加信息 - 我遇到的错误:
扩展类android.support.constraint.ConstraintLayout时出错
元素WebView不允许在这里