2017-05-15 31 views
5

Tôi đang cố gắng sử dụng Danh sách phát (React-native) trong ứng dụng của mình. Tôi đang sử dụng nó theo chiều ngang và có thể thấy thanh cuộn. Có một tùy chọn trong ScrollView để ẩn thanh cuộn nhưng không phải trong FlatList. Có ai có thể giấu nó theo một cách khác. Tôi đã thử sử dụng giải pháp của phụ huynh & thùng chứa trẻ em (Hide scroll bar, but still being able to scroll) nhưng không hoạt động.Ẩn thanh cuộn trong Danh sách Phẳng (React Native) trong Android

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; 
+4

thử 'showsHorizontalScrollIndicator = {sai} ' – Raymond

Trả lời

26

Chỉ cần thêm

showsHorizontalScrollIndicator={false} 
+0

Nó worke d nhưng nó không được đề cập trong tài liệu chính thức như là prop cho FlatList. –

0

thử này để làm cho ListView ngang add (ngang = {true}) đề cập dưới đây và nếu bạn chỉ muốn ẩn thanh cuộn chỉ cần thêm (showsHorizontalScrollIndicator = {false})

<ListView showsHorizontalScrollIndicator={false} 
         horizontal={true} 

/>

Các vấn đề liên quan