我想按原样加载值.我有两个dimension.xml文件,一个在/res/values/dimension.xml,另一个在/res/values-sw360dp/dimension.xml.
从源代码我想做的事情
getResources().getDimension(R.dimen.tutorial_cross_marginTop);
Run Code Online (Sandbox Code Playgroud)
这是有效的,但我获得的值乘以屏幕密度系数(hdpi为1.5,xhdpi为2.0等).
我也试过
getResources().getString(R.dimen.tutorial_cross_marginTop);
Run Code Online (Sandbox Code Playgroud)
这原则上可行,但我得到一个以"dip"结尾的字符串......
这是我的BindingAdapter:
@BindingAdapter(value = *arrayOf("bind:commentsAdapter", "bind:itemClick", "bind:avatarClick", "bind:scrolledUp"), requireAll = false)
fun initWithCommentsAdapter(recyclerView: RecyclerView, commentsAdapter: CommentsAdapter,
itemClick: (item: EntityCommentItem) -> Unit,
avatarClick: ((item: EntityCommentItem) -> Unit)?,
scrolledUp: (() -> Unit)?) {
//Some code here
}
Run Code Online (Sandbox Code Playgroud)
initWithCommentsAdapter 是一个顶级功能
这是我的布局(必不可少的部分):
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="some.example.path.CommentsViewModel"/>
<variable
name="commentsAdapter"
type="some.example.path.CommentsAdapter"/>
</data>
<android.support.v7.widget.RecyclerView
...
bind:avatarClick="@{(item) -> viewModel.avatarClick(item)}"
bind:itemClick="@{viewModel::commentClick}"
bind:commentsAdapter="@{commentsAdapter}"
bind:isVisible="@{viewModel.commentsVisibility}"
bind:scrolledUp="@{() -> viewModel.scrolledUp()}"
/>
</layout>
Run Code Online (Sandbox Code Playgroud)
当我在布局中使用kotlin方法调用分配lambda时,我在构建期间出现了这样的错误:
e: java.lang.IllegalStateException: failed to analyze:
java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:cannot find …Run Code Online (Sandbox Code Playgroud) 我试图使用软键盘的完成按钮通过数据绑定激活方法.就像onClick一样.有没有办法做到这一点?
例:
<EditText
android:id="@+id/preSignUpPg2EnterPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
onOkInSoftKeyboard="@{(v) -> viewModel.someMethod()}"
/>
Run Code Online (Sandbox Code Playgroud)
onOkInSoftKeyboard不存在...有什么东西可以创建这种行为吗?
谢谢!