这不是数据绑定,这是此处描述的 Android Studio 3.6 Canary 11+ 新增的视图绑定。
对于在 Activity 中使用,很明显,您只需像这样使用它:
假设我们有一个名为的布局 activity_main.xml
然后在代码中我们可以这样使用它:
public class MainActivity extends Activity{
ActivityMainBinding binding; //Name of the layout in camel case + "Binding"
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
}
}
Run Code Online (Sandbox Code Playgroud)
但是,不清楚如何将 View Binding 与 RecyclerView 一起使用?
编辑:请用Java解释。
我正在升级我的Android Studio,Gradle版本2.3到2.3.3,还更新了我的sdk - API级别26,SDK构建工具26,Google Play服务41,Google Repository 54.
当我清理我的项目时,我收到此错误: Failed to resolve: com.google.firebase:firebase-storage-common:11.0.1
的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
multiDexEnabled = true
}
def applicationVersion = '1.524 20170612'
dexOptions {
preDexLibraries = false
javaMaxHeapSize "2g"
}
...
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'build.gradle'
exclude 'build.xml'
exclude 'META-INF/jersey-module-version'
exclude 'META-INF/NOTICE'
}
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
}
}
dependencies {
compile 'com.fasterxml.jackson.core:jackson-core:2.9.0.pr1'
compile …Run Code Online (Sandbox Code Playgroud) 当我将 Android studio 从 3.3 更新到 3.4.1 时,我在 ImageView 标签中遇到了一些有趣的警告,例如:android:contentDescription attribute is unknown。我该如何解决这个警告?或者是新的Android Studio 3.4.1的bug?
android android-layout kotlin android-constraintlayout androidx