admin管理员组文章数量:1435859
I am trying to create a view with a border around it that is centered and fills 80% of the screen. I have e up with this:
<View style={{flexDirection: 'row'}}>
<View style={{flex: .1}} />
<View style={{flex: .8, borderWidth: 2}} />
<View style={{flex: .1}} />
</View>
which works, but seems awfully verbose.
Is there a better (more succinct) way to create a view that is a certain percentage of the screen width and centered in the page?
I am trying to create a view with a border around it that is centered and fills 80% of the screen. I have e up with this:
<View style={{flexDirection: 'row'}}>
<View style={{flex: .1}} />
<View style={{flex: .8, borderWidth: 2}} />
<View style={{flex: .1}} />
</View>
which works, but seems awfully verbose.
Is there a better (more succinct) way to create a view that is a certain percentage of the screen width and centered in the page?
Share Improve this question asked Jul 23, 2016 at 21:38 Abe MiesslerAbe Miessler 85.2k104 gold badges321 silver badges495 bronze badges1 Answer
Reset to default 6UPDATE:
Starting from React Native version 0.42 we now have a full percentage support for width
, height
, padding
and so on, see the full list and examples here:
https://github./facebook/react-native/mit/3f49e743bea730907066677c7cbfbb1260677d11
Old method:
Consider using Dimensions
, like:
import Dimensions from 'Dimensions';
and then in element's style:
width: Dimensions.get('window').width / 100 * 80,
Working example: https://rnplay/apps/4pdwlg
本文标签: javascriptHow to define width by percentage in react nativeStack Overflow
版权声明:本文标题:javascript - How to define width by percentage in react native? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745642583a2667945.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论