代碼很簡單,但是實用。在用listview時,用Divider分割,利用Expand即可讓上部分滾動但是跑馬燈卻可以固定不動。
@override Widget build(BuildContext context) { return SizedBox( height: 30, child: Card( // height: 40.0, color: Colors.blue[100], shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(10.0)), ), // 抗鋸齒
clipBehavior: Clip.antiAlias, elevation: 20, // 陰影大小 child: Container( height: 40, alignment: Alignment.bottomCenter, child: Center( child: Swiper( // autoplayDisableOnInteraction: true, // itemWidth: double.infinity, //containerHeight: 40, //itemHeight: 40, autoplayDelay: 8000, itemCount: l.length, // 對象個數 loop: true, // 允許循環播放 autoplay: true, // 允許自動播放 scrollDirection: Axis.vertical, // 滾動方向設置為水平 duration: 1000, // 執行時長 itemBuilder: (BuildContext context, int index) { return Text( listData[index], style: TextStyle(fontSize: 14, color: Colors.blue[800]), textAlign: TextAlign.center, textDirection: TextDirection.ltr, ); }, ))))); }
listData文件格式:
List listData = [
"人命至重,有貴千金,一方濟之,德逾於此。唐·孫思邈!\n進則救世,退則救民。東漢·張仲景。\n不為良相,亦為良醫。范仲淹。",
"喉干嗓啞時: 飲淡鹽水;服蜜梨膏;飲橘皮糖茶;\n常吃生梨能防治口舌生瘡和咽喉腫痛;\n臉上長痘痘時,口腔潰瘍時,咽喉疼痛時,綠豆湯有奇效。",
"初起感冒:蔥白(連須)、生姜5片,黑豆豉30粒、水一碗煎開,\n加適量紅塘一次服下(蔥姜不需服下),並馬上睡覺,出汗即愈。",
"北方多稱醫生為大夫,南方則以郎中為對醫生的敬稱。\n中醫的別名有:岐黃,青囊,杏林,橘井,懸壺,大夫,郎中。",
"山葯90克、百合40克、紅棗15個、薏米30克。\n百合清熱潤燥,紅棗、薏米滋陰健脾和胃。\n這粥有滋陰養胃、清熱潤燥的作用。",
];
點擊查看顯示效果:
http://www.pavogroup.top/images/Software/chinamedicine.mp4