2016-11-15 9 views
1

フレックスを使用して2列のグリッドを作成しようとしています。 1つの列は語句を表示するために使用され、2番目の列は最初の列の翻訳に使用されます。ここにリンク:http://imgur.com/nZGo8pb私は達成しようとしているものの視覚的なアイデアを与える。反応ネイティブで2つの列を作成しようとしています

2つの列を並べて表示することはできません。私は自分の言葉がお互いの上に現れるようにしかできません。これは最善の試みです。巨大な失敗。 http://imgur.com/a/ICApr

私のコードは次のとおりです。

nent} from 'react'; 
import { Text, View,StyleSheet,Image,TextInput,ListView} from 'react-native'; 

class AddWords extends Component{ 

    state = {words:['iku','konkai','kaikan'], 
      word:'', 
      EnglishWords:['go','this time','next time']  
      } 

    renderList(tasks){ 
     return(
     tasks.map((task) =>{ 
     return(
      <View key={task} style={styles.item}> 
      <Text> 
      {task} 
      </Text> 
       <Text> 
      </Text> 
      </View> 
      ) 

     }) 

    ) 
    } 
    renderEnglishWords(english){ 
     return(
     english.map((english) =>{ 
     return(
      <View key={english} style={styles.item2}> 
      <Text> 
      {english} 
      </Text> 
       <Text> 
      </Text> 
      </View> 
      ) 

     }) 

    ) 
    } 
    addWord(){ 
     let words = this.state.words.concat([this.state.word]); 
     this.setState({words}) 


    } 
    render(){ 
     return(
     <View style={styles.container}> 
      <TextInput 
      style={styles.input} 
      onChangeText={(word) => { 
       this.setState({word}) 
      }} 
      onEndEditing={()=>this.addWord()} 
      /> 
     <View style={styles.wordContainer}>  
      {this.renderList(this.state.words)} 
      {this.renderEnglishWords(this.state.EnglishWords)} 
      <View style={styles.item2}> 

      </View> 
      </View> 
     </View> 

     ) 
    } 

} 

const styles = StyleSheet.create({ 
    container:{ 
     flex:1, 
     borderWidth:3, 
     borderColor:'green', 
     flexDirection:'column', 
     paddingTop:10 

    }, 
    wordContainer:{ 

    flexDirection: 'column', 
    borderColor:'blue', 
    borderWidth:2 


    }, 
    input:{ 
     height:60, 
     borderWidth:1, 
     borderRadius:5, 
     borderColor:'black', 
     textAlign:'center', 
     margin:10, 
     paddingTop:20, 
     paddingBottom:10 

    }, 
    item:{ 
    borderColor:'red', 
    borderWidth:2 


    }, 
    item2:{ 
    borderColor:'black', 
    borderWidth:2, 
    flexDirection:'column', 
    } 
}) 
export default AddWords; 

すべてのヘルプは大歓迎されます。

ありがとうございました。

答えて

5

あなたは次のスタイルを持つ別の<View>の両方の内側のコンテナをラップする必要があります。

<View style={styles.container}> 
    <TextInput style={styles.input} 
      onChangeText={(word) => { 
      this.setState({word})}} 
      onEndEditing={()=>this.addWord()}/> 

    <View style={{flexDirection: 'row', flex: 1}}> 
    <View style={styles.wordContainer}> 
     ... 
    </View> 
    <View style={styles.item2}> 
     ... 
    </View> 
    </View> 
</View> 
0

それはstyles.wordContainerflexDirectionが「列」に設定されているので、それは「行」に設定する必要があります。

フレックス方向の例については、this linkを参照してください。

関連する問題