水平ScrollView切割子视图末端

时间:2018-08-18 06:43:45

标签: android react-native react-native-android react-native-scrollview

我有一个Scrollview,我将其设置为水平,但是当它不能完全显示组件时,它会剪切最后一个视图,或者如果子视图的宽度和高度较大,它将不会t显示所有视图,它仍然会剪切最后一个视图,我尝试更改仍剪切的contentContainerStyle,请问可能有什么错误

It cuts at the last view

下面是我的密码

   export default class Home extends Component {
    constructor(props) {
    const Width = Dimensions.get('window').width;
    super(props);
    this.state = {
        n: '0',
        no: 0,
        width: Width / 3
    };
 }
 return (
 <View style={styles.ox}>
 <View style={styles.firstColumn}>
  <Text style={styles.columnText}>
     Top Sold Items in your School{'\n'}
  </Text>
     <View style={styles.pictures}>
         <ScrollView contentContainerstyle={{flexGrow:1,
             flexDirection: 'row',}}  horizontal={true}
                     showsHorizontalScrollIndicator={false}
                     showsVerticalScrollIndicator={false}
                     automaticallyAdjustContentInsets={false}
                     directionalLockEnabled={true}
                     bounces={false}
                     scrollsToTop={false}>
             <View style={styles.miniPictures}>
         </View>
         <View style={styles.miniPictures}>
         </View>
             <View style={styles.miniPictures}>
             </View>
             <View style={styles.miniPictures}>
             </View>
             <View style={styles.miniPictures}>
             </View>
             <View style={styles.miniPictures}>
             </View>
         </ScrollView>
     </View>
 </View>
 </View>
    );
}
}
const dimensions = Dimensions.get('window');
const Height = (dimensions.height) / 5;
const Width = dimensions.width;
const styles = StyleSheet.create({
pictures: {
    flex: 1,
},
miniPictures: {
    height: 70,
    width: 70,
    marginRight: 10,
    borderTopRightRadius: 6,
    borderTopLeftRadius: 6,
    borderBottomLeftRadius: 6,
    borderBottomRightRadius: 6,
    backgroundColor: '#000',
    borderColor: '#d1d1d1'
},
columnText: {
    fontFamily: 'mont-medium',
    fontSize: 12,
    color: '#000'
},
firstColumn: {
    flexDirection: 'column',
    marginLeft: '6%',
    marginRight: '40%',
    paddingTop: 20,
    width: Width,
    height: 200
},
ox: {
    flexDirection: 'column',
    width: '100%',
    marginTop: 15,
},
headerCenter: {
    fontFamily: 'mont-bold',
    fontSize: 34,
    alignSelf: 'center',
    marginTop: 27,
    marginBottom: 14,
    letterSpacing: 0.7,
},
icons: {
    width: Width * (14.5/100),
    height: Width * (14.5/100),
    borderRadius: (Width* (14.5/100))/2,
    backgroundColor: '#F2C490',
    alignContent: 'center'
},
iconRow:{
    flex: 1,
    alignContent: 'center',
    justifyContent: 'space-between',
    marginLeft: 15,
    marginRight: 15,
    flexDirection: 'row'
}
});

1 个答案:

答案 0 :(得分:1)

问题:

firstColumn: {
    flexDirection: 'column',
    marginLeft: '6%',// Problem
    marginRight: '40%',
    paddingTop: 20,
    width: Width,// Problem
    height: 200
},

此样式的marginLeft为6%,但宽度仍为Width,您可以将宽度更改为 Width-Width * 0.12 或删除 marginLeft