整理 Android 常见错误

 1

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
	is also present at [androidx.core:core:1.2.0] AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory).
	Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:23:5-63:19 to override.

解决方法:

AndroidManifest.xml文件里的application里做如下添加:

android:appComponentFactory=""
        tools:replace="android:appComponentFactory"

 

 

2

Program type already present: com.google.android.material.internal.package-info

解决方法:

有两个包都引入了这个,删掉一个包,重新构建

 

3

More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'

解决方法:

在app的build.gradle加入如下报错提示的缺失代码:

packagingOptions {
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }

位置:

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    buildTypes {
        release {
            lintOptions {
                checkReleaseBuilds false
                abortOnError false
            }
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
    }

    packagingOptions {
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }
}

 

 

4.RecyclerView不调用onCreateViewHolder和onBindViewHolder

getItemCount()返回值<=0 

 

5.RecyclerView中getItemCount函数返回的数与实际生成的Item数量不一致

原因:item的layout的最外层布局的layout_width和layout_height不能是match_parent。如果recyclerView是横向排列的,item的width不能是match_parent,如果item是纵向排列的,item的height不能是match_parent。否则第一个item就会把其他的item挤出recyclerLayout

 

 

6.RecyclerView 滑动之后显示数据错乱(点击状态也错乱)

解决方法:重写Adapter的getItemViewType方法

/**
     * 解决RecyclerView 滑动之后显示数据错乱
     * 由于RecyclerView的onBindViewHolder()方法,
     * 只有在getItemViewType()返回类型不同时才会调用,
     * 这点是跟ListView的getView()方法不同的地方,
     * 所以如果想要每次都调用onBindViewHolder()刷新item数据,
     * 就要重写getItemViewType(),让其返回position,否则很容易产生数据错乱的现象
     */
    override fun getItemViewType(position: Int): Int {
        return position
    }

解决前:

解决后:

 

 

 

 

 

 

 

 

7.FrameLayout布局 点击事件无反应

解决方法:想点击的控件的层级被遮挡

1.在XML文件中,可以使用FramLayout或RelativeLayout来布局,每个控件都是覆盖显示的,后加进来的控件覆盖前面的控件。可以把控件写在最后,从而实现显示在最上层的效果。

2.view.bringToFront() 可以将布局在下层的控件放到上层,不被其他控件挡住。

 

 

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_唐宋元明清

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值