假设我有一个Earthquake有字段的类public final double magnitude;,我的布局类似于这个:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="earthquake" type="com.example.Earthquake"/>
</data>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@{String.format(earthquake.magnitude)}" />
...
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
注意我必须"@{String.format(earthquake.magnitude)}"使用此字段,否则我收到此错误:
在android.widget.TextView上找不到属性'android:text'的setter,参数类型为double.
不幸的是,这导致双重打印完全准确.如何格式化显示的double值?
Bar*_*end 26
我还没有看过M SDK预览中的绑定表达式语言,所以我可能会得出结论,但是如果调用普通String.format()方法,那么它需要一个模式.你试过这个吗?
android:text='@{String.format("%.1f", earthquake.magnitude)}'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4824 次 |
| 最近记录: |