ios - 如何在响应所有设备的 react-native 应用程序中设置 marginLeft 和 marginRight
问题描述
我需要为UI layout butto
n 设置 marginRight 和 left。如果我设置MarginLeft
和正确,它不会对所有设备都有响应。我需要在单一样式中为所有设备设置动态。
请澄清如何为ios
和android
设备编写 css 以响应所有设备
解决方案
Create a file called config.js and add the below code.
import { Dimensions } from 'react-native';
const config = {
deviceWidth: Dimensions.get('window').width,
deviceHeight: Dimensions.get('window').height
}
export default config
Then import this .js file to the file where you are going to styling.
import config from './config'
const styles = StyleSheet.create({
container: {,
paddingLeft: config.deviceWidth * 0.1,
width : config.deviceWidth * 0.8
}
});
This will align your label according to your device width. So this will responsive to every device.
Like this you can use paddingRight: config.deviceWidth * 0.2
to align from right.
By changing the value of x (deviceWidth * x) you can set margin as you want.
推荐阅读
- java - Java合并排序递归奇怪
- c - 如何在c中使用数组打开文件
- security - 通过命令行安全地发送密码而不暴露在 ps/wmic (Windows,Unix) 中
- javascript - 如何在javascript中访问row id并实现多行的展开/折叠?
- ios - 在ios中获取renewable in app产品购买的收据信息
- python - 尽管安装了torchvision,但无法加载它
- genetic-algorithm - 整洁:物种形成
- django - 使用基于 Django 类的 CreateView 执行多步骤表单
- css - Bootstrap 4 添加垂直分隔管
- microsoft-graph-api - 如何摆脱 Microsoft Access Data Anytime Consent?