2017-03-22 7 views
1

私のアプリに4:6の幅で2つのビューを入れて、それらの中にテキストを入れたいと思います。リアクションネイティブ:ビュー幅を固定

import React, { Component } from 'react'; 
import { AppRegistry, View , Text} from 'react-native'; 

class FixedDimensionsBasics extends Component { 
    render() { 
    return (
     <View style={{flex:1, flexDirection: "row"}}> 
     <View style={{flex:0.4, backgroundColor: 'powderblue'}}> 
      <Text>sfasdfadsfdasfas</Text> 
     </View> 
     <View style={{flex:0.6, backgroundColor: 'skyblue'}}> 
      <Text>sfasdfadsfdasfas</Text> 
     </View> 
     </View> 
    ); 
    } 
} 

AppRegistry.registerComponent('AwesomeProject',() => FixedDimensionsBasics); 

私はこの I want it like this

のようにそれをしたいが、私は横にテキストを追加するとき、それはこの but when I add text in side, it becomes like this

質問のようになる:固定幅との見解を維持する方法はありますし、テキストを幅で調整しますか?

ありがとうございます!

p.s.コード例&のデバッグにReact Native Docを使用します。

答えて

3

私は答えを見つけました。 flexBasis:0.4を使用してください。

import React, { Component } from 'react'; 
import { AppRegistry, View , Text} from 'react-native'; 

class FixedDimensionsBasics extends Component { 
    render() { 
    return (
     <View style={{flex:1, flexDirection: "row"}}> 
     <View style={{flex:0.4, flexBasis:0.4, backgroundColor: 'powderblue'}}> 
      <Text>sadfsfsdfasdfdsfasdsadfasdf</Text> 
     </View> 
     <View style={{flex:0.6, flexBasis:0.6, backgroundColor: 'skyblue'}}> 
      <Text>fasddfsadfsaf</Text> 
     </View> 
     </View> 
    ); 
    } 
} 

AppRegistry.registerComponent('AwesomeProject',() => FixedDimensionsBasics); 

次に、ビューが0.4の幅で固定されました。ここでenter image description here

はそれは私が探しています何、CSS CSS trick flex-base

+0

素晴らしいにおけるフレックスベースの説明です... – Shongsu

関連する問題