我嘗試創建這樣的事: 將相對於其他視圖在視圖陣營本地
正如你看到的,文本應放在相對較當天(以上爲中心)的標記。當你在前幾天和最後幾天時,它應該留在框架內,而不是在高標記上方居中。
我該如何做到這一點?
這是我當前的代碼:
組件
export default class DateLine extends Component {
render() {
const dots = (<View style={Styles.dotsContainer} >
{[...Array(DaysInCurrentMonth())].map((x, i) =>
<View key={i.toString()} style={[Styles.dot, (CurrentDayInMonth() === (i + 1) ? Styles.tallDot : null), (CurrentDayInMonth() < (i + 1) ? Styles.grayDot : null)]} />
)}
</View>);
return (
<View style={Styles.container}>
<Text style={Styles.text}>{GetDateWithMonthAsText(Date()).toUpperCase()}</Text>
{dots}
</View>
);
}
}
風格:
export default StyleSheet.create({
container: {
alignSelf: 'stretch',
marginHorizontal: 15
},
dotsContainer: {
height: 10,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end'
},
dot: {
backgroundColor: Colors.darkBlueGrey,
height: 5,
width: 5,
borderRadius: 2.5
},
tallDot: {
height: 10
},
grayDot: {
backgroundColor: Colors.pinkishGreyTwo
},
text: {
fontWeight: '600'
}
});
請告訴我們你到目前爲止嘗試過的東西! :-) – Andru
@Andru添加了我目前的代碼。這不會放置文本。 – PetterW