Question: I want to be able to to be able to set padding values if a boolean is true. The problem is that Android studio cannot parse the layout because it thinks 2dp is a decimal with a value of 2 and then doesn't know what to do with the p. how do I format this so that it understands i mean 2 density pixels.

Data layout:

```
<data class=".ItemBinding">
    <variable name="isGroupType" type="Boolean"/>
</data>

```

View layout(whats important):

```
<android.support.v7.widget.AppCompatImageView
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:paddingBottom='@{isGroupType ? 2dp : 0dp}'
            android:paddingTop='@{isGroupType ? 8dp : 0dp}'
            android:paddingRight='@{isGroupType ? 2dp : 0dp}'
            android:paddingLeft='@{isGroupType ? 2dp : 0dp}'/>

```

Answer: 
For anyone looking to set margins via DataBinding, you'll have to use `BindingAdapter` as well:

```
@BindingAdapter("layoutMarginBottom")
fun setLayoutMarginBottom(view: View, dimen: Float) {
    val layoutParams = view.layoutParams as MarginLayoutParams
    layoutParams.bottomMargin = dimen.toInt()
    view.layoutParams = layoutParams
}

```

And your xml property will look like this:

```
app:layoutMarginBottom="@{someCondition ? @dimen/zero_dp : @dimen/twenty_dp}"

```
You can use logic and ternary statements in xml-binding, but you really shouldn't. It will come back to haunt you when you're looking the usual places you have logic and don't see what's going on.
BindingAdapter for all your margin needs:

```
fun bindingSetMargins(view: View, start: Float?, top: Float?, end: Float?, bottom: Float?) {
    view.layoutParams = (view.layoutParams as ViewGroup.MarginLayoutParams).apply {
        start?.toInt()?.let { leftMargin = it }
        top?.toInt()?.let { topMargin = it }
        end?.toInt()?.let { rightMargin = it }
        bottom?.toInt()?.let { bottomMargin = it }
    }
}

```