在 Android 的 FlatList (React Native) 中隐藏滚动条

新手上路,请多包涵

我正在尝试在我的应用程序中使用 FlatList (React-native)。我水平使用它,可以看到滚动条。 ScrollView 中有一个选项可以隐藏滚动条,但 FlatList 中没有。有没有人能够以其他方式隐藏它。我尝试使用父子容器的解决方案( 隐藏滚动条,但仍然可以滚动)但没有奏效。

 import React, { Component } from 'react';
import { Text, View, FlatList, StyleSheet, ScrollView } from 'react-native';
import { Card, Button } from 'react-native-elements';

const data = [
    { id: 1, title: 'title 1', details: 'details 1 details 1 details 1' },
    { id: 2, title: 'title 2', details: 'details 2 details 2 details 2 details 2 details 2 details 2' },
    { id: 3, title: 'title 3', details: 'details 3 details 3' },
    { id: 4, title: 'title 4 title 4', details: 'details 4' },
];
class CategoryRow extends Component {

    _keyExtractor = (item, index) => item.id;

    _renderItem = (item) => {
        return (
            <Card style={styles.cardContainer}>
                <Text>{item.title}</Text>
                <Text>{item.details}</Text>
            </Card>
        );
    }

    render() {
        return (
            <View style={{ flex: 1, overflow:'hidden' }}>
                <View style={{ overflow:'hidden' }}>
                    <Text>Category 1</Text>
                    <FlatList
                        horizontal
                        data={data}
                        renderItem={({ item }) => this._renderItem(item)}
                        keyExtractor={this._keyExtractor}

                    />
                </View>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    cardContainer: {
        width: 140,
        height: 150,
        borderWidth: 0.5,
        borderColor: 'grey',
        overflow: 'scroll',
    },
})

export default CategoryRow;

原文由 sushil bansal 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.4k
2 个回答

禁用垂直和水平滚动指示器

<ScrollView
  showsVerticalScrollIndicator={false}
  showsHorizontalScrollIndicator={false}
 />

原文由 Muhammad Numan 发布,翻译遵循 CC BY-SA 4.0 许可协议

只需添加

showsHorizontalScrollIndicator={false}

原文由 Kawatare267 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题