搭建自己的直播平台,将图片设置为卡片式轮播效果

搭建自己的直播平台,将图片设置为卡片式轮播效果实现的相关代码

在app.gradle 添加:

 

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.github.xiaohaibin:XBanner:1.6.1'//将latestVersion替换成上面 jitpack 后面的版本号
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    annotationProcessor 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.zhy:okhttputils:2.0.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    // 一般依赖:
    implementation 'com.facebook.fresco:fresco:0.14.1'
    // 如果需要支持gif,再添加:
    implementation 'com.facebook.fresco:animated-gif:0.12.0'
}

​在project.gradle里面添加:

 

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

以上所有的依赖就完成了,下面就是代码部分:

因为我用的是模拟接口的图片地址,所以我是自己写了一段json,有需要的可以自行copy,要用自己的就在调用的部分换成自己的json就行:

 

public class Api {
    public static String jiek="{
"code": 800,
"msg": "ok",
"obj": [{
"name": "zahnsan",
"imageurl": "http://pic19.nipic.com/20120308/4970979_102637717125_2.jpg",
"age": "20"
}, {
"name": "zahnsan",
"imageurl": "http://pic25.nipic.com/20121110/10839717_103723525199_2.jpg",
"age": "20"
}, {
"name": "zahnsan",
"imageurl": "http://pic31.nipic.com/20130722/9252150_095713523386_2.jpg",
"age": "20"
}, {
"name": "zahnsan",
"imageurl": "http://www.pptbz.com/pptpic/UploadFiles_6909/201306/2013062320262198.jpg",
"age": "20"
}]
}";
}

 

先看布局部分:

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
 
    <com.stx.xhb.xbanner.XBanner
        android:id="@+id/banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:AutoPlayTime="3000"
        app:isAutoPlay="false"
        app:isClipChildrenMode="true"
        app:isHandLoop="true"
        app:isShowIndicatorOnlyOne="true"
        app:isShowNumberIndicator="false"
        app:isShowTips="false"
        app:pointsVisibility="false"
        app:pageChangeDuration="800"
        app:pointsPosition="RIGHT"/>
    
    <com.stx.xhb.xbanner.XBanner
        android:id="@+id/banner2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        app:AutoPlayTime="3000"
        app:isAutoPlay="false"
        app:pointsVisibility="false"
        app:isClipChildrenMode="true"
        app:isHandLoop="true"
        app:pageChangeDuration="800"/>
    
    <com.stx.xhb.xbanner.XBanner
        android:id="@+id/banner3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        app:AutoPlayTime="3000"
        app:clipChildrenLeftRightMargin="80dp"
        app:isAutoPlay="false"
        app:isClipChildrenMode="true"
        app:isHandLoop="true"
        app:isShowIndicatorOnlyOne="true"
        app:isShowNumberIndicator="false"
        app:pointsVisibility="false"
        app:pageChangeDuration="800" />
 
</LinearLayout>

 

以上就是搭建自己的直播平台,将图片设置为卡片式轮播效果实现的相关代码, 更多内容欢迎关注之后的文章

 

posted @ 2021-11-11 14:15  云豹科技-苏凌霄  阅读(203)  评论(0编辑  收藏  举报