flutter實(shí)現(xiàn)輪播圖效果
本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下
1 添加依賴庫(kù)
flutter_swiper: ^1.0.6
2 普通常用 圓點(diǎn)指示器自動(dòng)輪播圖

class SwiperViewDefaultPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new SwiperViewDefaultPageState();
}
}
class SwiperViewDefaultPageState
extends BaseAppBarPageState<SwiperViewDefaultPage> {
@override
String buildInitState() {
buildBackBar("輪播圖", backIcon: Icons.arrow_back_ios);
return null;
}
@override
Widget buildWidget(BuildContext context) {
print("build --");
return new Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(10),
),
buildStyle1(),
],
);
}
// 分頁(yè)指示器
buildSwiperPagination() {
return SwiperPagination(
//指示器顯示的位置
alignment: Alignment.bottomCenter, // 位置 Alignment.bottomCenter 底部中間
// 距離調(diào)整
margin: const EdgeInsets.fromLTRB(0, 0, 0, 5),
// 指示器構(gòu)建
builder: DotSwiperPaginationBuilder(
// 點(diǎn)之間的間隔
space: 2,
// 沒(méi)選中時(shí)的大小
size: 6,
// 選中時(shí)的大小
activeSize: 12,
// 沒(méi)選中時(shí)的顏色
color: Colors.black54,
//選中時(shí)的顏色
activeColor: Colors.white),
);
}
//banner 圖
Widget buildStyle1() {
return Container(
height: 200.0,
child: new Swiper(
// 橫向
scrollDirection: Axis.horizontal,
// 布局構(gòu)建
itemBuilder: (BuildContext context, int index) {
return new Image.network(
"http://hbimg.b0.upaiyun.com/a3e592c653ea46adfe1809e35cd7bc58508a6cb94307-aaO54C_fw658",
fit: BoxFit.fill,
);
},
//條目個(gè)數(shù)
itemCount: 6,
// 自動(dòng)翻頁(yè)
autoplay: true,
// 分頁(yè)指示
pagination: buildPlugin(),
//點(diǎn)擊事件
onTap: (index) {
print(" 點(diǎn)擊 " + index.toString());
},
// 相鄰子條目視窗比例
viewportFraction: 1,
// 布局方式
//layout: SwiperLayout.STACK,
// 用戶進(jìn)行操作時(shí)停止自動(dòng)翻頁(yè)
autoplayDisableOnInteraction: true,
// 無(wú)線輪播
loop: true,
//當(dāng)前條目的縮放比例
scale: 1,
),
);
}
buildPlugin() {
return SwiperPagination();
}
}
3 自定圓點(diǎn)分頁(yè)指示器 效果

//自定圓點(diǎn)分頁(yè)指示器
buildSwiperPagination() {
// 分頁(yè)指示器
return SwiperPagination(
//指示器顯示的位置
alignment: Alignment.bottomCenter, // 位置 Alignment.bottomCenter 底部中間
// 距離調(diào)整
margin: const EdgeInsets.fromLTRB(0, 0, 0, 5),
// 指示器構(gòu)建
builder: DotSwiperPaginationBuilder(
// 點(diǎn)之間的間隔
space: 2,
// 沒(méi)選中時(shí)的大小
size: 6,
// 選中時(shí)的大小
activeSize: 12,
// 沒(méi)選中時(shí)的顏色
color: Colors.black54,
//選中時(shí)的顏色
activeColor: Colors.white),
);
}
//定義輪播圖組件
Widget buildStyle1() {
return Container(
height: 200.0,
child: new Swiper(
// 橫向
scrollDirection: Axis.horizontal,
// 布局構(gòu)建
itemBuilder: (BuildContext context, int index) {
return new Image.network(
"http://hbimg.b0.upaiyun.com/a3e592c653ea46adfe1809e35cd7bc58508a6cb94307-aaO54C_fw658",
fit: BoxFit.fill,
);
},
//條目個(gè)數(shù)
itemCount: 6,
// 自動(dòng)翻頁(yè)
autoplay: true,
// 分頁(yè)指示
pagination: buildSwiperPagination(),
//點(diǎn)擊事件
onTap: (index) {
print(" 點(diǎn)擊 " + index.toString());
},
// 視窗比例
viewportFraction: 1,
// 布局方式
//layout: SwiperLayout.STACK,
// 用戶進(jìn)行操作時(shí)停止自動(dòng)翻頁(yè)
autoplayDisableOnInteraction: true,
// 無(wú)線輪播
loop: true,
scale: 1,
),
);
}
4 自定數(shù)字 分頁(yè)指示器 效果

//自定義分頁(yè)指示器
buildSwiperPagination() {
// 分頁(yè)指示器
return SwiperPagination(
//指示器顯示的位置
alignment: Alignment.bottomCenter, // 位置 Alignment.bottomCenter 底部中間
// 距離調(diào)整
margin: const EdgeInsets.fromLTRB(0, 0, 0, 5),
// 指示器構(gòu)建
builder: FractionPaginationBuilder(
// 選中時(shí)字體大小
activeFontSize: 14,
// 字體大小
fontSize: 14,
// 字體顏色
color: Colors.red,
//選中時(shí)的顏色
activeColor: Colors.blue),
);
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android ViewPager實(shí)現(xiàn)輪播圖效果
- Android自定義控件實(shí)現(xiàn)簡(jiǎn)單的輪播圖控件
- Android自定義控件實(shí)現(xiàn)優(yōu)雅的廣告輪播圖
- Android實(shí)現(xiàn)ViewPage輪播圖效果
- Android實(shí)現(xiàn)炫酷輪播圖效果
- Android實(shí)現(xiàn)基于ViewPager的無(wú)限循環(huán)自動(dòng)播放帶指示器的輪播圖CarouselFigureView控件
- 簡(jiǎn)單實(shí)現(xiàn)android輪播圖
- Android如何使用RecyclerView打造首頁(yè)輪播圖
- Android開(kāi)發(fā)在輪播圖片上加入點(diǎn)擊事件的方法
- Android實(shí)現(xiàn)輪播圖無(wú)限循環(huán)效果
相關(guān)文章
Android GPS室內(nèi)定位問(wèn)題的解決方法(location為null)
這篇文章主要為大家詳細(xì)介紹了Android GPS室內(nèi)定位問(wèn)題的解決方法,location為null,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
Android中阻止AlertDialog關(guān)閉實(shí)例代碼
這篇文章主要介紹了Android阻止AlertDialog關(guān)閉實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-03-03
SurfaceView播放視頻發(fā)送彈幕并實(shí)現(xiàn)滾動(dòng)歌詞
這篇文章主要為大家詳細(xì)介紹了SurfaceView播放視頻發(fā)送彈幕并實(shí)現(xiàn)滾動(dòng)歌詞,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11
Android?ViewPager你可能不知道的刷新操作分享
這篇文章主要為大家詳細(xì)介紹了Android中ViewPager你可能不知道的刷新操作,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,需要的可以參考一下2023-05-05
RxJava入門(mén)指南及其在Android開(kāi)發(fā)中的使用示例
RxJava是JVM的一個(gè)擴(kuò)展庫(kù),它能夠幫助Java更加方便地實(shí)現(xiàn)基于事件的編程,這對(duì)安卓來(lái)說(shuō)十分有用,接下來(lái)就一起來(lái)看一下RxJava入門(mén)指南及其在Android開(kāi)發(fā)中的使用示例:2016-06-06
Android自定義view實(shí)現(xiàn)倒計(jì)時(shí)控件
這篇文章主要為大家詳細(xì)介紹了Android自定義view實(shí)現(xiàn)倒計(jì)時(shí)控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-10-10
Android開(kāi)發(fā)中滑動(dòng)分頁(yè)功能實(shí)例詳解
這篇文章主要介紹了Android開(kāi)發(fā)中滑動(dòng)分頁(yè)功能,結(jié)合實(shí)例形式詳細(xì)分析了Android滑動(dòng)分頁(yè)功能的具體步驟與相關(guān)實(shí)現(xiàn)技巧,代碼中備有詳盡的注釋便于理解,需要的朋友可以參考下2017-10-10

