我想做width: 100% - 50
,这样我就可以添加一个图标,它是50宽的右手边.
我用react-native-extended-styles得到了width: 100% - 20%
,但我不明白为什么这是有用的,因为你可以做width: '80%'
.我无法工作.有办法吗?
try 使用onLayout
事件获取容器宽度,然后将容器宽度的<autocomplete>
设置为100% - 50
,但它不起作用.
let Location = (props) => {
let locationInputElement
const blur = () => {
locationInputElement.blur()
}
let inputContainerWidth
return (
<View style={styles.formItem}>
<View
onLayout={(event) => {
inputContainerWidth = event.nativeEvent.layout.width
console.log(inputContainerWidth)
}}
<Autocomplete
data={props.autocompleteResults.predictions}...
style={{
borderRadius: 8,
backgroundColor: 'red',
alignSelf: 'stretch',
paddingLeft: 10,
position: 'relative',
...styles.label,
...styles.labelHeight,
width: inputContainerWidth - 50
}}
/>
</View>
</View>
)
}
它确实是一种安慰.当它运行到控制台时记录335
.原木inputContainerWidth
,但<autocomplete>
的宽度仍然是335
%.