小编Ale*_*lex的帖子

数据绑定:如何将 xml 中的上下文传递给方法?

安卓工作室 3.0。

这是我的自定义方法:

public static int getTileWidthDpInScreen(Context context) {
    // some code here
    return tileWidthDp;
}
Run Code Online (Sandbox Code Playgroud)

这里是我的带有数据绑定代码的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <import type="com.myproject.android.customer.util.GUIUtil" />

    </data>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imageViewPhoto"
            android:layout_width="@{GUIUtil.getTileWidthDpInScreen()}"
            android:layout_height="@dimen/preview_image_height"
            android:scaleType="centerCrop"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />       


    </android.support.constraint.ConstraintLayout>

</layout>
Run Code Online (Sandbox Code Playgroud)

结果我得到错误:

e: java.lang.IllegalStateException: failed to analyze: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
data binding error msg:cannot find method getTileWidthDpInScreen() in class com.myproject.android.customer.util.GUIUtil
Run Code Online (Sandbox Code Playgroud)

这个错误是因为我没有在 method 中传递上下文getTileWidthDpInScreen()

我如何获得XML上下文,并将它传递的方法:getTileWidthDpInScreen()

android android-databinding

11
推荐指数
2
解决办法
6344
查看次数

数据绑定:属性缺少Androld名称空间前缀

Android Studio 3.0

classpath 'com.android.tools.build:gradle:3.0.1'
Run Code Online (Sandbox Code Playgroud)

  dataBinding {
        enabled = true
    }
Run Code Online (Sandbox Code Playgroud)

我想使用数据绑定.

这是我的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <data>
        <variable
            name="offer"  type="com.myproject.customer.Offer" />
    </data>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

Attribute is missing the Android namespace prefix
Run Code Online (Sandbox Code Playgroud)

android

9
推荐指数
1
解决办法
2288
查看次数

滑行:仅在顶部显示半径角的图像

我使用Glide。以下代码段:

Glide.with(context).load(referenceUrl).into(holder.imageViewPhoto);
Run Code Online (Sandbox Code Playgroud)

好。很好 但是我需要仅在TOP上显示带有圆角的图像。

像这样:

半径

Glide有可能吗?

android android-glide

6
推荐指数
1
解决办法
2348
查看次数

Android Studio 3.0:无法删除文件

安卓工作室 3.0

classpath 'com.android.tools.build:gradle:3.0.0'
Run Code Online (Sandbox Code Playgroud)

有时当我尝试启动应用程序时,我会收到下一个错误:

Error:java.io.IOException: Unable to delete file: myproject\common\build\intermediates\intermediate-jars\debug\classes.jar
> Unable to delete file: myproejct\common\build\intermediates\intermediate-jars\debug\classes.jar
Run Code Online (Sandbox Code Playgroud)

进程java.exe锁定了这个。为什么?

android android-studio-3.0

5
推荐指数
1
解决办法
1万
查看次数

SearchView:键盘不显示按钮完成

android 4.3.

片段:

 <android.support.v7.widget.SearchView
        android:id="@+id/searchView"
        style="@style/Widget.AppCompat.SearchView.ActionBar"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_marginEnd="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginStart="20dp"
        android:background="@drawable/search_view_bg"
        android:imeOptions="actionDone"
        android:maxLines="1"
        android:inputType="text"
        android:theme="@style/SearchViewTheme"
        app:defaultQueryHint="@null"
        app:layout_constraintLeft_toLeftOf="@+id/searchViewContainer"
        app:layout_constraintRight_toRightOf="@+id/searchViewContainer"
        app:layout_constraintTop_toTopOf="@+id/searchViewContainer"
        app:searchHintIcon="@null" />
Run Code Online (Sandbox Code Playgroud)

我想在点击SearchView时显示键盘上的Done按钮.所以我设置android:imeOptions="actionDone".但它没有帮助:

结果如下:

键盘

android searchview

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