我创建了一个自定义样式:
<style name="Static">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginEnd">5dp</item>
</style>
然后我用静态函数扩展了anko:
inline fun ViewManager.static(theme: Int = R.style.Static, init: TextView.() -> Unit) = ankoView(::TextView, theme, init)
当我在布局中使用它时:
static { text = resources.getString(R.string.name) }
marginEnd 值被忽略。
如果我在 anko 中手动添加边距:
static { text = resources.getString(R.string.name) }.lparams { marginEnd = dip(5) }
边距很好。
你们知道anko忽略了我的边距值或任何其他方式为扩展视图anko函数定义预定义边距的情况吗?