Android学习笔记——RecyclerView控件学习中遇到的问题与解决

RecyclerView学习中遇到的问题与解决

我下的Android studio是3.4.1,所正在学习的第一行代码第二版的AS版本是2.2,其中版本的差异可以说是很大的了。我在学习的过程因此也遇到了一些问题。

一、关于添加相应的依赖库
根据官网内容,应在build.grade中添加如下:

dependencies {
    implementation 'com.android.support:recyclerview-v7:28.0.0'//配置时会出现下划线,但是是正确的,可以成功添加
}

备注:新建的项目只要需要用到RecyclerView控件,就需要在app/build.grade当中添加一次依赖库。

二、运行后软件始终无响应

在activity_main.xml的编写

原本代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

在官网上查询这么写是没问题的。但是运行后软件始终无法响应。

在翻看其它部分的代码后觉得,还是这个布局代码最可能有一些问题才导致软件无法响应。

大量尝试后:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

这样写就可以正常运行了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值