Как я могу передать измерение в dp с привязкой данных с включенным макетом? - PullRequest
0 голосов

Я пытаюсь передать paddingTop для включенного макета, но не могу найти способ. Я пытаюсь передать измерение, определенное в файле ресурсов, int, помещая тип переменной в int и передавая dp. Единственный способ, которым я обнаружил, что это работает, - определить переменную как int и передать int.

Это включенный макет:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<data>

    <import type="android.view.View" />

    <variable
        name="image"
        type="android.graphics.drawable.Drawable" />

    <variable
        name="notification"
        type="int" />
    <variable
        name="paddingTop"
        type="androidx.annotation.Dimension" />

</data>

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:paddingTop="@{paddingTop}"
        android:layout_gravity="center">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingEnd="7dp"
            android:paddingBottom="7dp"
            tools:src="@drawable/ic_tab_home_selector"
            android:src="@{image}"/>

        <TextView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:background="@drawable/tab_notification_circle"
            android:fontFamily="@font/muli"
            android:gravity="center"
            android:text="@{String.valueOf(notification)}"
            android:textColor="@android:color/white"
            android:textSize="10sp"
            android:visibility="@{notification > 0 ? View.VISIBLE : View.GONE}" />


    </RelativeLayout>
</FrameLayout>

И вот как я пытаюсь передать измерение:

 <include
            android:id="@+id/tab_home"
            layout="@layout/layout_tab_item"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:notification="@{1}"
            app:paddingTop="@{4dp}"
            app:image="@{@drawable/ic_tab_home_selector}"/>
...