gpt4 book ai didi

java - android.widget.FrameLayout$LayoutParams 无法转换为 android.widget.AbsListView$LayoutParams

转载 作者:行者123 更新时间:2023-11-29 06:57:36 26 4
gpt4 key购买 nike

还有其他相关问题,但它们没有解决我的情况(它们的错误代码与客户端代码的某种回收和/或错误的转换调用有关)。

我的情况比较复杂。

我有一些代码,用户可以在其中调出照片库。

问题是,它在我拥有的 7 部手机上运行良好,所有手机都运行 API 19+。

但是我有一个运行 API 17 的 Google Nexus 4.3。我得到这个崩溃日志,其中没有我的代码,只有库代码。如果您能建议我如何编写解决方案,我会洗耳恭听:

FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
at android.widget.GridView.onMeasure(GridView.java:1042)
at android.view.View.measure(View.java:15848)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
at android.view.View.measure(View.java:15848)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
at android.view.View.measure(View.java:15848)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

更新

我的违规类(class)是这样的:

 //Special class that works with the UIL
//The holder gets re-used and gets the new properties from this
static class ReusableGridViewView extends FrameLayout
{
public ImageView imageView;
public ProgressBar progressBar;

public ReusableGridViewView(Context context)
{
super(context);

setLayoutParams(new LayoutParams((int)(0.325* ViewHelper.screenWidthPX(context)),(int)(0.325* ViewHelper.screenWidthPX(context))));

imageView = new ImageView(context);
progressBar = new ProgressBar(context);

addView(imageView);
addView(progressBar);
}
}

我正在使用 Ultimate Image Loader 库,这是使用上述类的代码。

 //I do NOT call this directly, the listview decides when re use a convert view and passes it accordingly
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
final ViewHolder holder;
View view = convertView;
if (view == null)
{
view = new ReusableGridViewView(parent.getContext());

holder = new ViewHolder();
assert view != null;
holder.imageView = ((ReusableGridViewView)view).imageView;
holder.progressBar = ((ReusableGridViewView)view).progressBar;
holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}

//System.out.println(" " + holder + " ||| " + holder.imageView);
ImageLoader.getInstance()
.displayImage(IMAGE_URLS[position], holder.imageView, options, new SimpleImageLoadingListener()
{
@Override
public void onLoadingStarted(String imageUri, View view)
{
holder.progressBar.setProgress(0);
holder.progressBar.setVisibility(View.VISIBLE);
}

@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason)
{
holder.progressBar.setVisibility(View.GONE);
}

@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage)
{
holder.progressBar.setVisibility(View.GONE);
}

}, new ImageLoadingProgressListener()
{
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total)
{
holder.progressBar.setProgress(Math.round(100.0f * current / total));
}
});

//set all as unselected
((ReusableGridViewView) view).removeSelectionBorder();
for(int i = 0; i < SELECTED_IMAGES.length; i++)
{
if(SELECTED_IMAGES[i] == position)
{
//set cell to selected
((ReusableGridViewView) view).addSelectionBorder();
}
}
return view;
}

最佳答案

事实证明,在 API < 17 上,FrameLayout 无法正确转换为 AbsListView 参数。

我所做的是设置 AbsListView LayoutParams 而不是 FrameLayout 参数:

    setLayoutParams(new AbsListView.LayoutParams(100,100));

关于java - android.widget.FrameLayout$LayoutParams 无法转换为 android.widget.AbsListView$LayoutParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31569468/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com