728x90
반응형
css를 만지다 보면 최대 너비로 하고싶을때
이상하게 width:100%가 안될때가 있다
난 초보라 왜그런지모른다
이럴땐 width를 screen 너비로 해주면 참 좋은데 알아보자
reactnative의 기본 api이다 import해주자
import {Dimensions} from 'react-native';
상단에 아무때나 변수를 초기화 해주자
Dimensions.get('window'). 를 이용하면 된다.
const Width = Dimensions.get('window').width; //스크린 너비 초기화
const Height = Dimensions.get('window').height; //스크린 높이 초기화
예시:
예를들어 이런 버튼이 있다 양쪽으로 꽉 차게 하고싶다.
<LinearGradient
start={{x: 0, y: 0}}
end={{x: 1, y: 0}}
colors={['#E94e68', '#eb6c63']}
style={styles.linearGradient}
style={{
display: 'flex',
flex: 0.1,
backgroundColor: '#E94e68',
justifyContent: 'center',
alignItems: 'center',
width: Width, <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<요기
//width: Dimensions.get('window').width를 직접써줘도 된다
}}>
<Text
style={{
fontSize: 18,
fontWeight: 'bold',
fontFamily: 'Jalnan',
color: 'white',
}}>
메세지 보내기
</Text>
</LinearGradient>
다음과 같이나온다
맨날 까먹어서 결국포스팅으로 남겨둔다
반응형
'react-native 공부' 카테고리의 다른 글
[reactnative] 로컬저장소 asyncstorage를 사용해보자 (0) | 2021.01.06 |
---|---|
[react-native]이미지(image)파일 적용 어케 할까? (2) | 2020.12.23 |
[react-native] SafeAreaView의 높이를 어케 구할까?(ios) (0) | 2020.11.04 |
[react-native] 키보드를 띄우면 input창을 가리지 않게 해보자 (KeyboardAwareScrollView) (1) | 2020.11.03 |
[react-native] 버튼을 누르면 alert 창을 띄워보자(ios) (1) | 2020.10.23 |