javascript - How to add a floating Action Button inside a scrollview at a specific position in React-Native Expo?
问题描述
I want to show a floating action button at bottom right side of my screen. But as I have one Scrollview component in my Screen I am not getting how should I do that? In the below image you can see-
there are some cards in the ScrollView but I want to show a floating action button at bottom right side of the screen which will overlap the Cards. So, it would be very nice if anyone suggest me with code - How can I do that?
解决方案
在 ScrollView 代码下方添加操作按钮并使其成为绝对值。这是一个工作示例代码
import React, { Component } from 'react';
import { StyleSheet, View, Alert, ListView, Text, TouchableOpacity, Image,ScrollView } from 'react-native';
export default class Mynewproject extends Component {
SampleFunction=()=>{
// Write your own code here, Which you want to execute on Floating Button Click Event.
Alert.alert("Floating Button Clicked");
}
render() {
return (
<View style={styles.MainContainer}>
<ScrollView>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
<Text>sdds</Text>
</ScrollView>
<TouchableOpacity activeOpacity={0.5} onPress={this.SampleFunction} style={styles.TouchableOpacityStyle} >
<Image source={{uri : 'https://reactnativecode.com/wp-content/uploads/2017/11/Floating_Button.png'}}
style={styles.FloatingButtonStyle} />
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
MainContainer :{
justifyContent: 'center',
flex:1,
margin: 10
},
TouchableOpacityStyle:{
position: 'absolute',
width: 50,
height: 50,
alignItems: 'center',
justifyContent: 'center',
right: 30,
bottom: 30,
},
FloatingButtonStyle: {
resizeMode: 'contain',
width: 50,
height: 50,
}
});
推荐阅读
- python-3.x - tensorflow 如何保持 l2_normalize 约束?
- office-js - Windows10 上的 Word 加载项本地侧载问题
- cron - 多个自定义 crontab 文件到一个主 crontab
- azure-aks - AKS 节点池升级失败,Azure 活动日志“操作超时,请重试”。
- python - IndexError:索引 6 超出轴 0 的范围,大小为 6
- android - 在 Android Webview 的 navigator.geolocation.getCurrentPosition() 中出现“位置信息不可用”错误
- c++ - 非 POD 的零初始化
- angular - 为什么在 Angular 中,在主组件 css 文件中导入全局 css 文件而不是在 styles.css 中导入它们之间存在很大差异
- kotlin - 你能定义 Kotlin Annotations 的替代简写吗?
- sql-server - SQL Server 降级到 2014 的权限问题 Windows 10