Android Studio com.android.support:percent 导入错误

看第一行代码(第二版的)书,讲了一个关于PercentFrameLayout和PercentRelativeLayout的部分,书上在build.gradle中导入了com.android.support:percent:24.2.1的包。
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    compile 'com.android.support:percent:24.2.1'
    testCompile 'junit:junit:4.12'

但Sync后显示错误

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 26.0.0-alpha1, 24.2.1. Examples include com.android.support:animated-vector-drawable:26.0.0-alpha1 and com.android.support:percent:24.2.1 less... (Ctrl+F1) 
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version 

所有com.android支持库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。发现版本26.0.0-alpha1 24.2.1。例子包括com.android.support:animated-vector-drawable:26.0.0-alpha1 com.android.support:百分比:24.2.1少…(Ctrl + F1)
有一些库、工具和库的组合是不兼容的,或者可能导致bug。一个这样的不兼容性是用Android支持库的版本编译,而不是最新的版本(特别是,比你的目标版本低的版本)。

这样就好解决了找到android SDK的文件夹I:\AndroidSDk\extras\android\m2repository\com\android\support\percent
在这里就能看到各种版本的,这里我选择26的26.0.0-alpha1,重新导入,之后重新Sync就可以了!

    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    compile 'com.android.support:percent:26.0.0-alpha1'
    testCompile 'junit:junit:4.12'
以下是Android Studio实现轮播图的步骤: 1.在app/build.gradle文件中添加依赖项: ```gradle dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:cardview-v7:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:palette-v7:28.0.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:support-vector-drawable:28.0.0' implementation 'com.android.support:animated-vector-drawable:28.0.0' implementation 'com.android.support:customtabs:28.0.0' implementation 'com.android.support:exifinterface:28.0.0' implementation 'com.android.support:preference-v7:28.0.0' implementation 'com.android.support:preference-v14:28.0.0' implementation 'com.android.support:percent:28.0.0' implementation 'com.android.support:mediarouter-v7:28.0.0' implementation 'com.android.support:gridlayout-v7:28.0.0' implementation 'com.android.support:leanback-v17:28.0.0' implementation 'com.android.support:cursoradapter:28.0.0' implementation 'com.android.support:documentfile:28.0.0' implementation 'com.android.support:localbroadcastmanager:28.0.0' implementation 'com.android.support:print:28.0.0' implementation 'com.android.support:slices-builders:28.0.0' implementation 'com.android.support:slices-core:28.0.0' implementation 'com.android.support:slices-view:28.0.0' implementation 'com.android.support:wear:28.0.0' implementation 'com.android.support:wear-watchface:28.0.0' implementation 'com.android.support:wear-remote-interaction:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:cardview-v7:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:palette-v7:28.0.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:support-vector-drawable:28.0.0' implementation 'com.android.support:animated-vector-drawable:28.0.0' implementation 'com.android.support:customtabs:28.0.0' implementation 'com.android.support:exifinterface:28.0.0' implementation 'com.android.support:preference-v7:28.0.0' implementation 'com.android.support:preference-v14:28.0.0' implementation 'com.android.support:percent:28.0.0' implementation 'com.android.support:mediarouter-v7:28.0.0' implementation 'com.android.support:gridlayout-v7:28.0.0' implementation 'com.android.support:leanback-v17:28.0.0' implementation 'com.android.support:cursoradapter:28.0.0' implementation 'com.android.support:documentfile:28.0.0' implementation 'com.android.support:localbroadcastmanager:28.0.0' implementation 'com.android.support:print:28.0.0' implementation 'com.android.support:slices-builders:28.0.0' implementation 'com.android.support:slices-core:28.0.0' implementation 'com.android.support:slices-view:28.0.0' implementation 'com.android.support:wear:28.0.0' implementation 'com.android.support:wear-watchface:28.0.0' implementation 'com.android.support:wear-remote-interaction:28.0.0' implementation 'com.youth.banner:banner:1.4.10' } ``` 2.在布局文件中添加Banner组件: ```xml <com.youth.banner.Banner android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="200dp" app:banner_indicatorGravity="center" app:banner_delay_time="3000" app:banner_is_auto_play="true" app:banner_scroll_time="1000" /> ``` 3.在Activity或Fragment中设置Banner的数据源和图片加载器: ```java // 设置数据源 List<String> images = new ArrayList<>(); images.add("http://img.zcool.cn/community/01c8dc5d6f1e6fa801219c77f8f8c9.jpg"); images.add("http://img.zcool.cn/community/01c8dc5d6f1e6fa801219c77f8f8c9.jpg"); images.add("http://img.zcool.cn/community/01c8dc5d6f1e6fa801219c77f8f8c9.jpg"); banner.setImages(images); // 设置图片加载器 banner.setImageLoader(new GlideImageLoader()); ``` 4.创建图片加载器类: ```java public class GlideImageLoader extends ImageLoader { @Override public void displayImage(Context context, Object path, ImageView imageView) { Glide.with(context).load(path).into(imageView); } } ``` 5.启动Banner轮播: ```java banner.start(); ```
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值