问题
I have a strange Error with a ViewGroup. For my main View I use classes in this links ViewFlow project
java.lang.IllegalArgumentException: parameter must be a descendant of this view
at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4153)
at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:4090)
at android.view.ViewRootImpl.scrollToRectOrFocus(ViewRootImpl.java:2129)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:1849)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1641)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2449)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
This error happens when I try to go back to this view with an Intent or a finish(); method in an other View. When I use the Back Button it's not a problem.
So i don't know why I have this Error. Thanks for your Help.
回答1:
Have the same problem. I use a ViewFlow as the parent view and several GridView as child views.This error happens when I press the Home key and restart the activity again after I scrolled these child views left and right.
Here is my solution:
mViewFlow.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
Of course, you can config it in layout.xml.
Hope that can help you.
回答2:
This works for me.
convertView = mInflater.inflate(R.layout.row_stat_header,
parent, false);
Here, parent
is the ViewGroup parameter in the getView.
回答3:
Solved my problem with adding scroll listener.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View currentFocus = ((Activity)mContext).getCurrentFocus();
if (currentFocus != null) {
currentFocus.clearFocus();
}
}
来源:https://stackoverflow.com/questions/10721907/java-lang-illegalargumentexception-parameter-must-be-a-descendant-of-this-view