Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android databinding set padding if value is true

Tags:

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}'/> 
like image 922
BillHaggerty Avatar asked May 27 '16 15:05

BillHaggerty


1 Answers

Store padding value in dimen.xml and use it. Please keep habit to write binding string with " " (double quotes)

android:paddingBottom="@{isGroupType ? @dimen/padding_normal : @dimen/padding_null}" 

and so on for other paddings also.

like image 109
Ravi Avatar answered Sep 28 '22 06:09

Ravi