我构建了react-native 应用程序,并与scrollView一起使用标题和水平文本列表.

带有滚动视图的屏幕

            <View style={Style.container} >
                {this.props.ExtendedNavigationStore.HeaderTitle ? <BackHeader header={this.props.ExtendedNavigationStore.HeaderTitle} onPressBack={this.goBack} /> : <Header openDrawer={this.openDrawer} />}
                <ScrollView  contentContainerStyle={{flexGrow:1}} style={Style.scrollableView} horizontal showsHorizontalScrollIndicator={false}>
                    {this.renderScrollableHeader()}
                </ScrollView>
                <Routes /> /* stack with dashboard screen */
            </View>
        </Drawer>

    )
}

风格

import {StyleSheet} from 'react-native'
import {calcSize} from '../../utils'


const Styles = StyleSheet.create({
    container : {
        flex:1,  
        backgroundColor:"#e9e7e8"      
    },
    scrollableView:{
        height: calcSize(40),
        backgroundColor: '#000',

    },
    textCategory:{
        fontSize: calcSize(25),
        color:'#fff'
    },
    scrollableButton:{
        flex:1,
        margin:calcSize(30)
    }
})

export default Styles

enter image description here

正如你所看到的,黑色大小是滚动视图,

在"路由堆叠到仪表板"屏幕中,样式:

const Style = StyleSheet.create({
    container: {
        backgroundColor: '#9BC53D',
        flex: 1,
        justifyContent: 'space-around',
        alignItems: 'center'
    },
    text: {
        fontSize: 35,
        color: 'white',
        margin: 10,
        backgroundColor: 'transparent'
    },
    button: {
        width: 100,
        height: 75,
        margin: 20,
        borderWidth: 2,
        borderColor: "#ecebeb",
        justifyContent: "center",
        alignItems: "center",
        borderRadius: 40
    }
})

推荐答案

现有限制为ScrollView,其中height不能直接提供

喜欢

  render() {
    return (
      <View style={styles.container}>
        <View style={{height: 80}} >
          <ScrollView
            horizontal
            style={{ backgroundColor: 'blue'}}
          >
            <Text style={{padding: 24}} >title1</Text>
            <Text style={{padding: 24}} >title2</Text>
            <Text style={{padding: 24}} >title3</Text>
            <Text style={{padding: 24}} >title4</Text>
            <Text style={{padding: 24}} >title5</Text>
          </ScrollView>
        </View>
      </View>
    );
  }

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
  },
});

snack sample: https://snack.expo.io/HkVDBhJoz

额外要求:与高度不同,将宽度设置为ScrollView将正常工作

希望这有帮助.

React-native相关问答推荐

FlatList有时不会在数据更改时重新呈现

使用下拉菜单时react 本机react-native-dropdown-select-list,它会将下面的项目向下移动.如何阻止这种情况发生

NPM INSTALL 在 react-native 项目上失败:无法解析 react 和 react-dom 的依赖树

如何在react-native 的switch 内显示文本(是/否)

给定 APK 文件,我如何检测应用程序是否使用 React Native?

Invariant Violation:requireNativeComponent: "RNCWebView" was not found in the UIManager

可以在没有 await 关键字的情况下调用异步函数吗?

SyntaxError: const 声明中缺少初始化程序

在配置 react-native-maps 中获取 "supportLibVersion" 、 "playServicesVersion" 和 "androidMapsUtilsVersion" 值

React Native 中的原生广告

在 react-native-maps 中渲染多个标记

React Native require(image) 返回数字

更改按钮 colored颜色 onPress(切换功能)

如何在样式组件之外获取主题?

错误 React Native CLI 对本机依赖项使用自动链接,但以下模块是手动链接的

Jest TransformIgnorePatterns 所有 node_modules 用于 React-Native Preset

如何在 React 中将函数与钩子绑定?

发布未使用 JavaScript 代码更新的 APK

将 colored颜色 变量导入我的样式

如何定义react-native应用程序的入口点