I was facing WRAP_CONTENT not work on a RecyclerView , so I googled it and found the workaround. When I tried to implement the workaround in c#, I was stuck at this line:
insetsDirtyField = RecyclerView.LayoutParams.class.getDeclaredField("mInsetsDirty");
Here I tried to port the original java code,and ported code avilable in gist
I was stuck at this line:
insetsDirtyField = RecyclerView.LayoutParams.class.getDeclaredField("mInsetsDirty");
The .class "keyword" in Java is equivalent to the typeof() keyword in C#, so this is (kinda/sorta) like:
var insetsDirtyField = typeof(RecyclerView.LayoutParams).GetDeclaredField("mInsetsDirty");
Except it isn't, because typeof() returns a System.Type, which doesn't know anything about java.lang.Object instances.
Instead, you should use Java.Lang.Class.FromType(Type) to obtain a Java.Lang.Class instance, which will then allow you to use Java Reflection:
var klass = Java.Lang.Class.FromType (typeof (RecyclerView.LayoutParams));
var insetsDirtyField = klass.GetDeclaredField("mInsetsDirty");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With