Get size of a View in React Native

前端 未结 7 1830
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 15:56

Is it possible to get the size (width and height) of a certain view? For example, I have a view showing the progress:



        
相关标签:
7条回答
  • 2020-11-29 16:45

    You can directly use the Dimensions module and calc your views sizes. Actually, Dimensions give to you the main window sizes.

    import { Dimensions } from 'Dimensions';
    
    Dimensions.get('window').height;
    Dimensions.get('window').width;
    

    Hope to help you!

    Update: Today using native StyleSheet with Flex arranging on your views help to write clean code with elegant layout solutions in wide cases instead computing your view sizes...

    Although building a custom grid components, which responds to main window resize events, could produce a good solution in simple widget components

    0 讨论(0)
提交回复
热议问题