Skip to content

Instantly share code, notes, and snippets.

@pfn
Created November 23, 2015 17:12
Show Gist options
  • Save pfn/409d2ca8ccc47c71432d to your computer and use it in GitHub Desktop.
Save pfn/409d2ca8ccc47c71432d to your computer and use it in GitHub Desktop.
layout.perform should create a new instance
override def onCreateView(i: LayoutInflater, c: ViewGroup, b: Bundle) = {
adapter foreach (_.context = getActivity)
val v = layout.perform()
def inputHeight = for {
a <- MainActivity.instance
h <- a.inputHeight
} yield h
log.v("view hash: " + System.identityHashCode(v) + " " + System.identityHashCode(this) + " " + System.identityHashCode(layout))
// why is this only occurring on gingerbread?
if (v.getParent != null) {
v.getParent.asInstanceOf[ViewGroup].removeView(v)
}
inputHeight.fold {
v.getViewTreeObserver.addOnPreDrawListener(new OnPreDrawListener {
override def onPreDraw() = {
inputHeight exists { h =>
v.getViewTreeObserver.removeOnPreDrawListener(this)
val p = v.getPaddingBottom + h
v.setPadding(
v.getPaddingLeft, v.getPaddingTop, v.getPaddingRight, p)
true
}
}
})
}{ h =>
val p = v.getPaddingBottom + h
v.setPadding(v.getPaddingLeft, v.getPaddingTop, v.getPaddingRight, p)
}
v
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment