相关疑难解决方法(0)

从源代码中加载res/values/dimension.xml中的维度值

我想按原样加载值.我有两个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"结尾的字符串......

android dpi dimension android-resources

319
推荐指数
8
解决办法
18万
查看次数

Android数据绑定:Kotlin中的@BindingAdapter无法识别lambdas

这是我的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)

android kotlin android-databinding

10
推荐指数
2
解决办法
1391
查看次数

在数据绑定中使用键盘上的完成按钮

我试图使用软键盘的完成按钮通过数据绑定激活方法.就像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不存在...有什么东西可以创建这种行为吗?

谢谢!

android android-databinding

3
推荐指数
3
解决办法
3509
查看次数