Kotlin / anko

Pleasant Android application development
Apache License 2.0
15.9k stars 1.28k forks source link

something issues of anko.include() dsl #759

Open gfzy9876 opened 4 years ago

gfzy9876 commented 4 years ago

inline fun <T: View> Context.include(layoutId: Int, init: (@AnkoViewDslMarker T).() -> Unit): T { @Suppress("UNCHECKED_CAST") return ankoView({ ctx -> ctx.layoutInflater.inflate(layoutId, null) as T }, 0) { init() } } inline fun <T: View> Activity.include(layoutId: Int, init: (@AnkoViewDslMarker T).() -> Unit): T { @Suppress("UNCHECKED_CAST") return ankoView({ ctx -> ctx.layoutInflater.inflate(layoutId, null) as T }, 0) { init() } } I use include to help me of inflating View in custom view, and recyclerView's item ,but some times is not simply, for example: when i want to inflate an RecyclerView item, i will call Inflater.from.inflate(R.layout.xxxx,parents, false); when i want to just create a View, i will call Inflater.from.inflate(R.layout.xxx, null, false); when i want to create a custom View,i will call Inflter.from.inflate(R.layout.xxx, this, true);

but anko not support to put the enough parameters to select.

also: i want to create a Linearlayout by anko in activity, but don't set it to ContentView ,I can't call Activity.include instead of Context.include, so i must force convert 'Activity' to 'Context', that makes me entangled