当前位置:网站首页>"Viewpager" and banner in compose
"Viewpager" and banner in compose
2022-07-20 20:15:00 【Li Xiaobai LT】
Preface
Compose There is no native similar in the Library ViewPager and Banner Of controls , although google Official "ViewPager", But it is still a beta version :
implementation "com.google.accompanist:accompanist-pager:0.24.2-alpha"
So we come to realize one by ourselves "ViewPager"(ComposePager) and Banner
Text
ComposePager
Have a look first ComposePager To achieve the effect of :
The code is also simple :
to glance at api:
/**
* Be similar to xml Medium ViewPager
* [pageCount] How many pages are there in all
* [modifier] modification
* [composePagerState]ComposePager The state of
* [orientation] The direction of the slide
* [userEnable] Whether the user can slide , be equal to false When the user slides, there is no response , But the code can turn pages
* [content]compose Content area
*/
@Composable
fun ComposePager(
pageCount: Int,
modifier: Modifier = Modifier,
composePagerState: ComposePagerState = rememberComposePagerState(),
orientation: Orientation = Orientation.Horizontal,
userEnable: Boolean = true,
content: @Composable ComposePagerScope.() -> Unit
)
among composePagerState Namely ComposePager The state of , If you don't need to monitor or modify the internal state , Then use the default
principle :
Refer to the RecyclerView and ViewPager, Equivalent to three all the time View, first View Put it on ( Left ) Noodles , the second View Show in the middle , Third View Put it down ( Right ) Noodles , When sliding, you can slide the other two out , When the hand is released, the movement animation will be performed and the three View The state of
Banner
Sample code :
api:
/**
* It can automatically rotate ComposePager
* [pageCount] How many pages are there in all
* [modifier] modification
* [bannerState]Banner The state of
* [orientation] The direction of the slide
* [userEnable] Whether the user can slide , be equal to false When the user slides, there is no response , But the code can turn pages
* [autoScroll] Whether to scroll automatically
* [autoScrollTime] Auto scroll interval
* [content]compose Content area
*/
@Composable
fun Banner(
pageCount: Int,
modifier: Modifier = Modifier,
bannerState: BannerState = rememberBannerState(),
orientation: Orientation = Orientation.Horizontal,
userEnable: Boolean = true,
autoScroll: Boolean = true,
autoScrollTime: Long = 3000,
content: @Composable BannerScope.() -> Unit
)
principle :
Inside of it... Is used ComposePager, Pass in pageCount*n Become an infinite loop , Then start an internal process , Keep calling ComposePager Of State Switch to the next page api And that's what happened Banner
Introduce projects
In the root project build.gradle Add... To the document :
allprojects {
repositories {
maven { url 'https://jitpack.io' }
...
}
}
app Of build.gradle Medium plus , Latest version reference :https://jitpack.io/#ltttttttttttt/ComposeViews
dependencies{
...
implementation 'com.github.ltttttttttttt:ComposeViews:1.0.9'
}
Then you can use it happily ComposePager and Banner 了
The project is open source , welcome star:GitHub - ltttttttttttt/ComposeViews
And there are more than ComposePager, There are more easy to use Compose Components , such as :
FlowLayout
GoodTextField and PasswordTextField
More will be added later Compose Components
end
边栏推荐
猜你喜欢
随机推荐
STL 笔记(八):容器——list
TZC 1283: 简单排序 —— 希尔排序
Japanese verbs + verb types + verb flexibility
科学计算库Numpy基础&提升(理解+重要函数讲解)
一文看懂深圳半导体产业现状与未来发展机遇
外表简单内里复杂的功能测试,如何进行?
GPS、基站、IP定位的区别及其应用方向
Golang interview - code writing questions 1-14
469-82(62、63、343、96)
30亿美元!地平线成全球估值最高AI芯片独角兽
CodeBlocks download + interface optimization + create file + common shortcut keys
Masonry小技巧之UIScrollView自适应
日语动词+动词类型+动词活用
uniapp自定义应用退出执行内容
Example: inference with pretrained nnU-Net models
9.mysql多个sql语句用到同一个具体值的写法
启牛开通的华泰账户用着安全吗?
STEPN链游系统开发模式详解(运动赚钱模式)
Masonry tips: uiscrollview adaptation
重装Win10系统怎么办?