我怎样才能只显示第一行文字?如果我有这样的东西:

<View> 
  <Text>
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, 
  </Text>
</View>

我只想有"Contrary to popular belief, Lorem Ipsum"个人出现.

推荐答案

您可以使用props numberOfLines限制文本溢出:

<Text numberOfLines={1}>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, 
</Text>

这将在达到父视图的限制时包装文本,如:

 Contrary to popular belief, Lorem Ipsum is not...

React-native相关问答推荐

领带麦克风在Reaction-Native-Incall-Manager中不工作

在 react native 平面列表中动态定位弹出窗口

如何修复 React Native 中任务:app:processDebugManifest的执行失败?

如何判断 Detox 正在运行测试?

找不到变量 atob

为什么会出现此错误:Invariant Violation: Cannot update during an existing state transition

Invariant Violation:requireNativeComponent: "RNCWebView" was not found in the UIManager

在 CircleCI 上 ReactNative 0.59.x build fails on CircleCI with exit value 137

react native 中 componentDidMount 和 componentDidUpdate 有什么区别

React Native 上传到 S3 存储空间

React-Native:save user preferences

在整个屏幕上获取touch 事件

在 Windows 上进行本机调试

error TS2300: Duplicate identifier 'RequestInfo'

React Navigation - 标题的渐变 colored颜色

为什么 Android Studio 强制使用 Android 支持库中的 Androidx?

错误:无法解析模块`buffer`

在本react-native中具有异步和等待的箭头函数

React Native Bullet Character? or Unicode?

如何在 React Native 中等待 Alert 对话框的响应?