美文网首页
布局文件使用中文问题

布局文件使用中文问题

作者: 吃惊馆长 | 来源:发表于2017-04-10 17:28 被阅读0次
<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text='@{"姓名:" + user.name}' />  String user.name 正确
<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text='@{user.lolita ? "萝莉" : "不是萝莉"}' /> boolean user.lolita 正确
<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text='@{user.age + "岁数"}' /> int user.age 正确

注意事项
使用中文字符串相加的时候必须是偶数,如果是奇数如

<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text='@{user.age + "岁"}' />

就会编译失败


解决办法
在strings.xml 定义中文,然后在布局文件引用
android:text='@{user.age + @string/sui}'

相关文章

网友评论

      本文标题:布局文件使用中文问题

      本文链接:https://www.haomeiwen.com/subject/dkxeattx.html