我目前正在努力調整一些影像大小React Native......我有一個容器,里面有一些影像,但我需要調整影像大小,使其完全適合小容器(不裁剪影像)。
這是我目前擁有的:
container: {
flex: 1,
flexDirection: 'row',
width: width / cardsPerRow,
marginLeft: customPadding / 2,
marginRight: selectDeviceType({ Tv: scale(3, 0) }, customPadding / 2),
marginBottom: selectDeviceType({ Tv: scale(15, 0) }, scale(20)),
marginTop: selectDeviceType({ Tv: 0 }, 0),
shadowOffset: { width: 0, height: 2 },
shadowColor: '#000',
shadowOpacity: 0.15,
shadowRadius: 1,
elevation: 0,
borderRadius: selectDeviceType({ Tv: 0 }, cardRadius),
},
wrapperStyle: {
height: selectDeviceType({ Handset: scale(77) }, scale(85)),
width: selectDeviceType({ Handset: scale(134) }, scale(165)),
aspectRatio: AspectRatio._16by9,
borderRadius: selectDeviceType({ Tv: 0 }, cardRadius),
overflow: 'hidden',
resizeMode: 'contain',
backgroundColor: 'red'
},
imageStyle: {
aspectRatio: AspectRatio._16by9,
width: "100%",
height: '100%',
flex: 1,
resizeMode: 'contain',
},
Container Class 是整個卡片部分,并且wrapperStyle是影像容器......所以你可能會看到影像沒有調整大小來修復wrapperstyle屬性,而不是自動調整大小wrapperStyle,影像只是裁剪掉了。關于如何解決這個問題的任何想法?
uj5u.com熱心網友回復:
請試試這個,可能對你有幫助
\ 添加調整大小模式
<Image
style={styles.imageStyle}
source={{uri:imageUrl}}
resizeMode='contain'
/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/431313.html
上一篇:ReactnativeWARN可能未處理的PromiseRejection(id:2):Error:[AsyncStorage]Passingnull/undefinedasvalueisnotsup
