search
HomeWeb Front-endHTML TutorialReactNative之Flex布局总结_html/css_WEB-ITnose

从二月份开始学习ReactNative到现在已经有两个月了,零碎的记录了很多笔记,一直想写一些ReactNative相关的东西,奈何感觉自己学习的还比较浅陋,而且笔记比较杂乱,不知从何而起,所以迟迟没有动笔。清明三天假,决定无论如何都得整一篇出来。本来是想整一篇ReactNative布局篇的,但是看看那么多布局属性,自己对CSS又不是特别熟悉,布局篇从何谈起?所以,专门拿出ReactNative中布局比较重要的一个点Flex布局来做下总结,算是开启ReactNative篇章。

Flex是Flexible Box的缩写,意为“弹性布局”,2009年它由W3C提出了一种新的网页布局方案。而FaceBook将这个布局也应用到React和ReactNative两个项目当中。而在ReactNative当中,网页的有些属性和属性的值并不支持,下面来看看ReactNative当中支持的属性。(如果对于Flex布局不太了解的同学,可以看看 Flex 布局教程:语法篇)

一、容器属性:

ReactNative支持的容器属性有flexDirection、flexWrap、justifyContent和alignItems。

1、 flexDirection属性

flexDirection属性决定了主轴的方向,它有两个值:

  • row: 主轴为水平方向,起点在左端
  • column: 主轴为垂直方向,起点在顶部

2、flexWrap属性

flexWrap属性定义一条轴线排不下时是否折行。它有两个值,分别是'wrap'和'nowrap',分别代表支持换行和不支持换行,默认是'nowrap'。

3、justifyContent属性

主轴的对齐方式,默认为'flex-start',它的值有五个:

  • flex-start:主轴起点对齐
  • flex-end:主轴终点
  • center:居中
  • space-between:两端对齐,项目之间的间隔都相等
  • space-around: 每个项目两侧的间隔相等。项目之间的间隔比项目与边框的间隔大一倍。

4、alignItems属性

交叉轴的对齐方式,默认为'stretch',它有四个值:

  • flex-start: 交叉轴的起点对齐
  • flex-end: 交叉轴的终点对齐
  • center: 交叉轴的中心对齐
  • stretch: 容器中的所有项目拉伸填满整个容器

二、项目属性

1、flex属性

是否让当前的视图尽量占用更大的空间,这个属性可能使项目属性justifyContent失效。有两个值0和1,0代表否,1代表是,默认为0。

2、alignSelf属性

允许单个项目在交叉轴方向上与其他项目不一样的对齐方式,可覆盖alignItems属性,它的值有五个,除了'auto',其他都与alignItem属性完全一致,默认为'auto'。

后话

在刚开始接触ReactNative的时候,对于我这么一个从未有过前端开发的iOS开发程序员,两个地方直接让我懵了,一是里面的语法,另外一个就是Flex布局。布局当中其它例如bottom、left、margin等等属性都能从字面意思理解,而Flex布局,确实是从没见过的东西,不理解里面的概念根本没法用。好在找到了阮一峰老师的 Flex 布局教程:语法篇的这篇文章,快速的掌握了Flex布局。 在这几天ReactNative的开发当中,越发觉得Flex布局的重要性,能将上面的属性全部理解清楚的话,并且灵活使用,必然会让ReactNative开发之旅更加得心应手。

参考:

Flex 布局教程:语法篇 弹性盒(Flexbox)

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment