Jac*_*lla 8 android include android-databinding
我正在尝试传递包含布局的 paddingTop 但我找不到方法。我尝试传递资源文件中定义的 dimen,一个 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>
Run Code Online (Sandbox Code Playgroud)
这就是我试图传递维度的方式:
<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}"/>
Run Code Online (Sandbox Code Playgroud)
您需要将变量声明为 Float
<variable
name="paddingTop"
type="Float" />
Run Code Online (Sandbox Code Playgroud)
然后你可以将尺寸传递给布局
<YourLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:paddingTop="@{@dimen/yourDimen}"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1738 次 |
| 最近记录: |