【发布时间】:2016-01-15 18:29:32
【问题描述】:
我正在使用 Android 的绑定库,我正在尝试根据布尔值在 TextView 上添加或删除边距。如果是真的,我希望 TextView 在右边有一个边距,在左边没有边距,如果没有,则相反。所有其他资源都可以正常工作,但是当我编译代码时,我收到有关 TextView 上边距的错误:找不到参数类型为 float 的属性“android:layout_marginRight”的设置器。
谁能发现错误?
这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="comment" type="mx.com.corpogas.dataModels.FeedbackComment"/>
<import type="android.view.View"/>
</data>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@{comment.isMine ? @drawable/comment_background_white : @drawable/comment_background_green}"
android:textSize="15sp"
android:textColor="@{comment.isSent ? (comment.isMine ? @color/colorPrimaryDark : @android:color/white) : @color/unsent_text}"
android:layout_marginRight="@{comment.isMine ? @dimen/feedback_comment_margin : @dimen/feedback_comment_no_margin}"
android:layout_marginLeft="@{comment.isMine ? @dimen/feedback_comment_no_margin : @dimen/feedback_comment_margin}"
android:text="@{comment.content}"/>
</layout>
这是我的利润:
<dimen name="feedback_comment_margin">16dp</dimen>
<dimen name="feedback_comment_no_margin">0dp</dimen>
当我删除边距时,程序编译并完美运行。
【问题讨论】:
标签: android xml data-binding