
我们知道在微信小程序中是不能直接给view设置本地图片的。那么我们怎么解决这个问题呢?
(学习视频分享:编程入门)
解决方法如下:
1、使用网络图片
2、使用base64格式
3、使用image来装载本地的图片,然后作为界面背景
前面两种都很简单,下面我们重点来讲讲第三种。一般大家的苦恼都是这么把imageview放到界面的最下面。那么下面直接上代码。
wxml
<view class="root">
<image class='background-image' src='../res/login_bg.png' mode="aspectFill"></image>
<view class="content">
</view>
</view>
wxss
.root {
width: 100%;
height: 100%;
background-color: #70c7da;
position: relative;
}
.background-image{
height : 100%;
position: absolute;
width: 100%;
left: 0px;
top: 0px;
}
.content{
position: absolute;
width: 100%;
height: 100%;
left: 0px;
top: 0px;
}
好了,搞定。只要用相对布局,就可以实现了。类似an
.........................................................