我在我的kotlin活动中使用Anko DSL布局。我无法为FAB设置下限。正确的保证金工作
在我的活动中
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(application as SamfantozziApp).dgaeacomponent().inject(this)
InvoiceListKtActivityUI(_rxBus).setContentView(this)
}
我的Anko DSL布局InvoiceListKtActivityUI.kt
class InvoiceListKtActivityUI (val _rxBus: RxBus): AnkoComponent<InvoiceListKtActivity>{
override fun createView(ui: AnkoContext<InvoiceListKtActivity>): View = with(ui){
return relativeLayout{
padding = dip(5)
lparams {
width = matchParent
height = wrapContent
margin = 5
}
verticalLayout{
tabLayout{
lparams {
width = matchParent
height = wrapContent
}
id = R.id.tabs
}
viewPager{
lparams {
width = matchParent
height = matchParent
}
id = R.id.container
}
}
floatingActionButton{
lparams {
width = wrapContent
height = wrapContent
rightMargin = 40 //works
bottomMargin = 40 //does not work
alignParentBottom()
alignParentRight()
}
imageResource = android.R.drawable.ic_input_add
id = R.id.fabinvoice
onClick{
_rxBus.send(InvoiceListFragment.ClickFobEvent())
}
}
}
}
}
答案 0 :(得分:0)
我认为您没有正确设置lparams。正确的形式是:
floatingActionButton {
imageResource = android.R.drawable.ic_input_add
}.lparams{
rightMargin = dip(16)
bottomMargin = dip(16)
alignParentBottom()
alignParentRight()
}