简体   繁体   English

React Native Android上的网格视图

[英]Grid view on React Native Android

I'm trying to create a scrollable, grid-like ListView on React Native Android. 我正在尝试在React Native Android上创建一个可滚动的,类似网格的ListView。

I found this, and it looks exactly like what I want to do: https://github.com/yelled3/react-native-grid-example 我找到了,它看起来和我想做的完全一样: https : //github.com/yelled3/react-native-grid-example

However the style is messed up on Android, the wrap doesn't appear to work. 但是,样式在Android上混乱不堪,自动换行似乎不起作用。 I have 2 lines, I can't see all my elements... 我只有2行,看不到我所有的元素...

我的数据源中有50个元素

Is it supposed to be supported on Android? 是否应该在Android上受支持? Or do I have to take a completely different approach? 还是我必须采取完全不同的方法? (ie have one component per line and manually break up my datasource) (即每行只有一个组件并手动分解我的数据源)

You can try this example from react-native repo https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/ListViewGridLayoutExample.js 您可以从react-nativehttps://github.com/facebook/react-native/blob/master/Examples/UIExplorer/ListViewGridLayoutExample.js尝试此示例

worked well for me on both platforfms. 在两个平台上对我来说都工作得很好。

It's better to share your code here if you want a more detailed answer. 如果您想获得更详细的答案,最好在这里共享您的代码。

The problem that you are having where you can't see all of your rows is most likely due to the navbar. 您无法看到所有行的问题很可能是由于导航栏。 Assuming you have a flex: 1 on the view, the row elements are appearing BEHIND the navbar. 假设您有一个flex: 1视图上的flex: 1 ,行元素显示在导航栏之后。

A possible solution is to figure out the size of navbar and then use that to figure out the size of the view below the navbar. 一种可能的解决方案是找出导航栏的大小,然后使用该值来找出导航栏下方的视图的大小。 You can then render your grid inside the calculated view. 然后可以在计算的视图内渲染网格。

Something along these lines: 遵循以下原则:

const NavHeightPadding = Platform.OS === 'ios' ? 64 : 54
const { width, height } = Dimensions.get('window');
const ViewHeight = { height: height - NavHeightPadding }

<View style={[{ marginTop: NavHeightPadding }, ViewHeight]}>
  ...some grid component
</View>

As for how to create the grid, you can take a look at @chukcha's answer where he provides a very good resource from facebook's examples. 至于如何创建网格,您可以看看@chukcha的答案,他在facebook的示例中提供了很好的资源。

A few other grid alternatives are: 其他一些网格替代方法是:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM