![](/img/trans.png)
[英]React Native - How to make portion of TouchableOpacity not pressable
[英]React Native: How to make TouchableOpacity shrink to fit Text contents?
我的 React Native 應用程序中有一個TouchableOpacity
,里面有一個Text
組件,我希望TouchableOpacity
的寬度與Text
一樣寬。 我試過這樣做:
<TouchableOpacity style={{flexDirection: 'row', flexBasis: 0, flexShrink: 1}}>
<Text>text</Text>
</TouchableOpacity>
但是TouchableOpacity
仍然和整個屏幕一樣寬。 flexGrow
默認為 0,所以我想通過允許TouchableOpacity
使用flexShrink
縮小並使其flexBasis
為零,
您可以將 alignself 樣式用於 TouchableOpacity
<TouchableOpacity style={{backgroundColor: 'red', alignSelf: 'flex-start' }}>
<Text>text</Text>
</TouchableOpacity>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.