我工作在應用中的問題製作相對於另一個維度陣營本地
陣營原住民,我需要的圖像有,即,它的高度爲寬度的一定比例。
代碼
在圖片中,背景是與內部另一圖像的圖像。我正在使用樣式化的組件。
export const ImageWithButtonStyled = styled.TouchableOpacity`
padding: ${Spacing.XLarge}
alignItems: center
width: 50%
`;
export const ImageWithButtonImageContentStyled = styled.View`
`;
export const ImageWithButtonBackgroundStyled = styled.Image`
marginLeft: ${Spacing.Large}
marginRight: ${Spacing.Large}
backgroundColor: ${Color.GrayLight}
borderWidth: 1
borderColor: ${Color.Gray}
justifyContent: center
alignItems: center
width: 100%
`;
export const ImageWithButtonButtonContentStyled = styled.View`
alignSelf: stretch
alignContent: center
`;
這是他們如何在一個組件render()
方法被使用:
render() {
return (
<ImageWithButtonStyled>
<ImageWithButtonBackgroundStyled source={null}>
<Image source={require('../assets/ic_photo/ic_photo.png')}/>
</ImageWithButtonBackgroundStyled>
<ImageWithButtonButtonContentStyled>
<LinkButton text={this.props.buttonText} />
</ImageWithButtonButtonContentStyled>
</ImageWithButtonStyled>
);
}
我正在尋找
我要找的結果是這樣的:
但是不必硬編碼任何尺寸,僅使用百分比並將高度設置爲寬度的百分比,以便灰色框可以在任何屏幕中保持我定義的高寬比,並進行相應的縮放。所以,如果我說高度是寬度的1.4倍,那麼該方面將保持在任何屏幕上。
任何幫助非常感謝,謝謝。
看一看[反應 - 本機可擴展的圖像(https://www.npmjs.com/package/ react-native-scalable-image) –