《第一行代码》读书笔记(一)

3.6节 recyclerView 添加依赖

书中在build.gradle文件内使用的是compile命令,现在不再支持,将命令改为implementation,如下:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.android.support:recyclerview-v7:24.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

相应地,在xml文件中引用recyclerView控件时,使用androidx库,标签如下:

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

4.4节 动态加载布局

这里需要添加一个layout-large/activity_main.xml,不过操作的时候会报错:重复文件名(尽管这个与默认的activity_main.xml不在同一个路径下),这似乎是AS新增的功能,如下图:
在这里插入图片描述
解决方法:
右键layout-large–>New–>layoutsoursefile即可(最后一步不要点那个xml),如下图:
在这里插入图片描述

发布了75 篇原创文章 · 获赞 61 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/swy_swy_swy/article/details/104760079