搭建自己的直播平台,将图片设置为卡片式轮播效果
搭建自己的直播平台,将图片设置为卡片式轮播效果实现的相关代码
在app.gradle 添加:
1 | dependencies {<br> implementation fileTree(dir: 'libs' , include: [ '*.jar' ])<br> implementation 'com.android.support:appcompat-v7:27.1.1' <br> implementation 'com.android.support:support-v4:27.1.1' <br> implementation 'com.android.support.constraint:constraint-layout:1.1.3' <br> testImplementation 'junit:junit:4.12' <br> androidTestImplementation 'com.android.support.test:runner:1.0.2' <br> androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' <br> implementation 'com.github.xiaohaibin:XBanner:1.6.1' //将latestVersion替换成上面 jitpack 后面的版本号<br> implementation 'com.github.bumptech.glide:glide:3.7.0'<br> annotationProcessor 'com.github.bumptech.glide:glide:3.7.0'<br> implementation 'com.zhy:okhttputils:2.0.0'<br> implementation 'com.google.code.gson:gson:2.8.5'<br> // 一般依赖:<br> implementation 'com.facebook.fresco:fresco:0.14.1'<br> // 如果需要支持gif,再添加:<br> implementation 'com.facebook.fresco:animated-gif:0.12.0'<br>} |
在project.gradle里面添加:
1 | allprojects {<br> repositories {<br> google()<br> jcenter()<br> maven { url 'https://jitpack.io' }<br> }<br>} |
以上所有的依赖就完成了,下面就是代码部分:
因为我用的是模拟接口的图片地址,所以我是自己写了一段json,有需要的可以自行copy,要用自己的就在调用的部分换成自己的json就行:
1 | public class Api {<br> public static String jiek= "{<br>" code ": 800,<br>" msg ": " ok ",<br>" obj ": [{<br>" name ": " zahnsan ",<br>" imageurl ": " http: //pic19.nipic.com/20120308/4970979_102637717125_2.jpg",<br>"age": "20"<br>}, {<br>"name": "zahnsan",<br>"imageurl": "http://pic25.nipic.com/20121110/10839717_103723525199_2.jpg",<br>"age": "20"<br>}, {<br>"name": "zahnsan",<br>"imageurl": "http://pic31.nipic.com/20130722/9252150_095713523386_2.jpg",<br>"age": "20"<br>}, {<br>"name": "zahnsan",<br>"imageurl": "http://www.pptbz.com/pptpic/UploadFiles_6909/201306/2013062320262198.jpg",<br>"age": "20"<br>}]<br>}";<br>} |
先看布局部分:
1 | <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" <br> xmlns:app= "http://schemas.android.com/apk/res-auto" <br> xmlns:tools= "http://schemas.android.com/tools" <br> android:layout_width= "match_parent" <br> android:orientation= "vertical" <br> android:layout_height= "match_parent" <br> tools:context= ".MainActivity" ><br> <br> <com.stx.xhb.xbanner.XBanner<br> android:id= "@+id/banner" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> app:AutoPlayTime= "3000" <br> app:isAutoPlay= "false" <br> app:isClipChildrenMode= "true" <br> app:isHandLoop= "true" <br> app:isShowIndicatorOnlyOne= "true" <br> app:isShowNumberIndicator= "false" <br> app:isShowTips= "false" <br> app:pointsVisibility= "false" <br> app:pageChangeDuration= "800" <br> app:pointsPosition= "RIGHT" /><br> <br> <com.stx.xhb.xbanner.XBanner<br> android:id= "@+id/banner2" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:layout_marginTop= "10dp" <br> app:AutoPlayTime= "3000" <br> app:isAutoPlay= "false" <br> app:pointsVisibility= "false" <br> app:isClipChildrenMode= "true" <br> app:isHandLoop= "true" <br> app:pageChangeDuration= "800" /><br> <br> <com.stx.xhb.xbanner.XBanner<br> android:id= "@+id/banner3" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:layout_marginTop= "10dp" <br> app:AutoPlayTime= "3000" <br> app:clipChildrenLeftRightMargin= "80dp" <br> app:isAutoPlay= "false" <br> app:isClipChildrenMode= "true" <br> app:isHandLoop= "true" <br> app:isShowIndicatorOnlyOne= "true" <br> app:isShowNumberIndicator= "false" <br> app:pointsVisibility= "false" <br> app:pageChangeDuration= "800" /><br> <br></LinearLayout> |
以上就是搭建自己的直播平台,将图片设置为卡片式轮播效果实现的相关代码, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现