スライドレイアウトは、アプリや小さなプログラムで非常に一般的な要件です。一般的な要件として、この要件を効率的に満たす方法は非常に重要です。アプリでは、recycleview、listview、scrollviewなどのレイアウトで、アップルトで0から1へのスライドレイアウトを実現する方法は?この記事をご覧ください
結果を示す
列内の複数のアイテムの全体的な分布を確認できます。指を使用して左右にスライドできます。
コントロールレイアウト
wxmlファイル
<view class="module-group">
<view class="module-title">
<view class="titlename">电影</view>
<!--“更多”点击跳转的-->
<navigator class="more">更多</navigator>
</view>
<scroll-view class="scroll-view" scroll-x="{true}}">
<navigator class=" item-scrollview ">
<view class="item-group ">
<view class="thumbnail-group ">
<image class="thumbnail " src="https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2576090251.jpg ">
</image>
</view>
<view class="movie-name ">误杀误杀误杀误杀误杀误杀误杀</view>
</view>
</navigator>
<navigator class=" item-scrollview ">
<view class="item-group ">
<view class="thumbnail-group ">
<image class="thumbnail " src="https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2576090251.jpg ">
</image>
</view>
<view class="movie-name ">误杀</view>
</view>
</navigator>
<navigator class=" item-scrollview ">
<view class="item-group ">
<view class="thumbnail-group ">
<image class="thumbnail " src="https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2576090251.jpg ">
</image>
</view>
<view class="movie-name ">误杀</view>
</view>
</navigator>
<navigator class=" item-scrollview ">
<view class="item-group ">
<view class="thumbnail-group ">
<image class="thumbnail " src="https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2576090251.jpg ">
</image>
</view>
<view class="movie-name ">误杀</view>
</view>
</navigator>
</scroll-view>
</view>
wxssファイル
/**index.wxss**/
.module-group{
padding: 40rpx;
background: #fff;
}
.module-group .module-title{
font-size: 32rpx;
display: flex;
justify-content: space-between; /**字体贴着两边**/
}
.module-title .titlename{
color: #494949;
}
.module-title .more{
color: #41be57;
}
.scroll-view {
margin-top: 40rpx;
width: 100%;
height: 400rpx;
white-space: nowrap; /** 不换行 **/
}
.scroll-view .item-scrollview{
width: 200rpx;
margin-right: 20rpx; /**和右边间距**/
display: inline-block;/** 一行展示 **/
}
/** 定制最后一个item布局 **/
.scroll-view .item-scrollview:last-of-type{
margin-right: 0; /**保障不多出来一个margin-right 20rpx**/
}
.item-scrollview .item-group{
width: 100%;
}
.item-group .thumbnail-group{
width:100%;
height: 284rpx;
}
.thumbnail-group .thumbnail{
width: 100%;
height: 100%;
}
.item-group .movie-name{
font-size: 28rpx;
text-align: center;
margin-top: 20rpx;
text-overflow: ellipsis; /** 超出的字用省略号代替 **/
overflow: hidden;
}
主な詳細
レイアウトには注意が必要な詳細がいくつかあります
1.タイトルステッカーの両側のレイアウト分布
justify-content: space-between;
この機能は、justify-contentを使用して実現できます
2.エリプシス
text-overflow: ellipsis; /** 超出的字用省略号代替 **/
overflow: hidden;
3.最後に表示されたアイテムをカスタマイズして、最終的なレイアウトの左右の余白が一定になるようにします
/** 定制最后一个item布局 **/
.scroll-view .item-scrollview:last-of-type{
margin-right: 0; /**保障不多出来一个margin-right 20rpx**/
}
友達のように、好きに、そして集めてください〜