所以我希望看到我的布局预览,其中的字段填充了类似默认占位符的字段但是如果我使用绑定,则已经使用了settext属性,并且字段显示为空,因为模型中还没有信息.
<TextView
android:id="@+id/tv_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:gravity="center"
**android:text="@{showBlueportSpotViewModel.name}"**
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"/>
Run Code Online (Sandbox Code Playgroud)
我试过这个:
android:text="@{showBlueportSpotViewModel.name ?? @string/blueport_placeholder_name}"
Run Code Online (Sandbox Code Playgroud)
但我仍然认为这个视图是空的.
你们有任何解决方法吗?我想一旦找到一个解决方法,它可以用于ImageView和src等示例.
谢谢!
bla*_*kcj 19
您可以使用tools属性定义将在布局预览中显示的属性,但在运行应用程序时不会显示.
将以下内容添加到根视图中:
xmlns:tools="http://schemas.android.com/tools"
Run Code Online (Sandbox Code Playgroud)
然后使用tools属性定义仅出现在布局预览中的文本:
tools:text="placeholder text"
Run Code Online (Sandbox Code Playgroud)
在编辑器中模拟视图时,tools属性非常有用.打包应用程序时会删除所有工具属性.更多信息请访问:http://tools.android.com/tech-docs/tools-attributes
| 归档时间: |
|
| 查看次数: |
6291 次 |
| 最近记录: |