React-Native native-base How to decrease the spacing between card Items?

淺唱寂寞╮ 提交于 2019-12-10 14:16:19

问题


render() {
  return(
    <Card style={{  padding: 0 }}>
      <CardItem listItemPadding={0} header style=styles.Card}>
        <Text style={styles.cardText}>
          {this.props.library.title}
        </Text>
      </CardItem>
    </Card>
  );
}

The docs say that listItemPadding can be used but it's not working I have tried to change the padding of to 0 but it's not working either.


回答1:


I see that you are trying to use listItemPadding prop which doesn't exist at the moment.

ListItem, Card and CardItems, each have some padding or margin of their own. You can just inspect the screen, check it and remove the padding/margin as per your requirement using style. Or you can eject NativeBase theme (Customize) and do your changes in the theme of those components. That way you will have the same styles for those components in your whole app.

Probably you are looking for a paddingVertical property. You can add a negative value and then edit your component style as you will normally do.

native-base-theme/components/CardItem.js

paddingVertical: variables.cardItemPadding - 5,

Then on your component:

render() {
  return(
    <Card style={{  padding: 10 }}>
      <CardItem header style={{ paddingTop: 10 }}>
        <Text>Item</Text>
      </CardItem>
    </Card>
  );
}



回答2:


Use the cardBody attribute in cardItem it will work.




回答3:


try this code:

render() {
        return(

<View style={{  flex: 0,
 elevation: 3,
 shadowColor: "#000",
 shadowOpacity: 0.1,
 shadowOffset: { width: 0, height: 2 },
 shadowRadius: 1.0,
 marginVertical: 1,
 borderRadius: 2,
 marginHorizontal: 1,
 margin: 0,
 padding: 0,
borderWidth: 0, }}>

                 <CardItem listItemPadding={0} header style=styles.Card}>
                     <Text style={styles.cardText}>
                         {this.props.library.title}
                     </Text>
                 </CardItem>

             </View>

        );
    }


来源:https://stackoverflow.com/questions/48166731/react-native-native-base-how-to-decrease-the-spacing-between-card-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!