我正在尝试在 RecyclerView 的每个项目中使用 ProgressWheel。
每次添加 ProgressWheel 后,它都会给我以下异常:
05-04 18:33:06.311: E/AndroidRuntime(738): FATAL EXCEPTION: main
05-04 18:33:06.311: E/AndroidRuntime(738): android.view.InflateException: Binary XML file line #36: Error inflating class <unknown>
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-04 18:33:06.311: E/AndroidRuntime(738): at com.example.v2.adapter.WallpaperRVGridAdapter.onCreateViewHolder(WallpaperRVGridAdapter.java:131)
05-04 18:33:06.311: E/AndroidRuntime(738): at com.example.v2.adapter.WallpaperRVGridAdapter.onCreateViewHolder(WallpaperRVGridAdapter.java:1)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:4385)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3700)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3609)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1859)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:356)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1274)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:525)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:151)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2118)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2415)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.View.layout(View.java:7175)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.os.Looper.loop(Looper.java:123)
05-04 18:33:06.311: E/AndroidRuntime(738): at android.app.ActivityThread.main(ActivityThread.java:3647)
05-04 18:33:06.311: E/AndroidRuntime(738): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 18:33:06.311: E/AndroidRuntime(738): at java.lang.reflect.Method.invoke(Method.java:507)
05-04 18:33:06.311: E/AndroidRuntime(738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-04 18:33:06.311: E/AndroidRuntime(738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-04 18:33:06.311: E/AndroidRuntime(738): at dalvik.system.NativeStart.main(Native Method)
05-04 18:33:06.311: E/AndroidRuntime(738): Caused by: java.lang.reflect.InvocationTargetException
05-04 18:33:06.311: E/AndroidRuntime(738): at java.lang.reflect.Constructor.constructNative(Native Method)
05-04 18:33:06.311: E/AndroidRuntime(738): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
05-04 18:33:06.311: E/AndroidRuntime(738): at andro
布局 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ProgressWheel="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/RelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/ximgvwWallpaperThumb"
android:layout_width="@dimen/wallpaper_thumb_size"
android:layout_height="@dimen/wallpaper_thumb_size"
android:background="@color/black"
android:padding="5dp"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/ximgvwWallpaperDownload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/ximgvwWallThumb"
android:padding="5dip"
android:src="@drawable/wallpaper_download_btn" />
</LinearLayout>
<com.todddavies.components.progressbar.ProgressWheel
android:id="@+id/xprogbarWallpaper"
android:layout_width="75dip"
android:layout_height="75dip"
android:layout_centerInParent="true"
android:layout_gravity="center"
ProgressWheel:barColor="#ff9a0000"
ProgressWheel:barLength="30dp"
ProgressWheel:barWidth="10dp"
ProgressWheel:rimColor="#FFF"
ProgressWheel:rimWidth="5dp"
android:visibility="visible" />
</RelativeLayout>
适配器方法:
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType)
{
// TODO Auto-generated method stub
final View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.wallpaper_grid_item, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position)
{
}
最佳答案
最后,通过使用不同的 Custom ProgressBar View DonutProgress 而不是 ProgressWHeel 来解决它。
ProgressWheel 似乎有问题,但找不到确切原因。
关于android - 如何在 recyclerview 项目中使用自定义 View ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30031173/